简体   繁体   English

SQL Server CE 3.5尽早切断字符串(C#)

[英]SQL Server CE 3.5 cuts off strings early (C#)

Hey Everyone, I am writing some code that makes use of SQL Server CE 3.5 and I am having a very strange problem. 大家好,我正在编写一些使用SQL Server CE 3.5的代码,但遇到了一个非常奇怪的问题。 I have a string field in one of the tables that needs to store a full file path. 我在需要存储完整文件路径的表之一中有一个字符串字段。

Over the course of trying to fix this problem I have that field set as nvarchar with a max size of 4000, but it is still cutting longer strings that are much shorter than the limit off 在尝试解决此问题的过程中,我将该字段设置为最大大小为4000的nvarchar ,但它仍在剪切更长的字符串,这些字符串比限制的长度短得多。

for example: 例如:

D:\iTunes\iTunes Media\Music\Abigail Williams\In The Absence Of Light\02 Final Destiny Of The Gods.m

This is clearly smaller than 4000 characters, yet it is missing the p3 at the end of the string. 明显小于4000个字符,但在字符串末尾缺少p3

I am using a table adapter to enter the data into the database with the following query: 我正在使用表适配器通过以下查询将数据输入数据库:

INSERT INTO [Track] ([Artist_ID], [Album_ID], [FilePath], [LastUpdate]) 
VALUES (@Art, @Al, @Fp, @LU)

I know that the strings are fully formed on insert because I am using the following code to check: 我知道字符串在插入时完全形成,因为我正在使用以下代码进行检查:

if(!temp.Filepath.EndsWith(".mp3"))
    MessageBox.Show("File Error");
this.trackTableAdapter1.InsertQuery(ArtID, AlID, temp.Filepath, File.GetLastWriteTime(temp.Filepath));

The message box does not get shown, so the string must end correctly on insert. 该消息框未显示,因此字符串在插入时必须正确结束。

the query that extracts the data is: 提取数据的查询是:

SELECT
   *
FROM Track
WHERE Artist_ID=@Artist_ID AND Album_ID=@Album_ID

The involved code is: 涉及的代码是:

foreach (Database.MusicDBDataSet.TrackRow TR in this.trackTableAdapter1.GetAlbumTracks(AR.Artist_ID, AlR.Album_ID).Rows)
{
   //if (!TR.FilePath.EndsWith(".mp3"))
   //MessageBox.Show("File Path Error");
   this.ArtistList[AR.Name].AlbumList[this.ArtistList[AR.Name].AlbumList.Count - 1].TrackList.Add(new Track(TR.FilePath, AlR.Name, AR.Name));
}

Has anyone ever run into this problem before? 有人遇到过这个问题吗?

Check the XSD file. 检查XSD文件。 Specifically, check the FilePath column of your table and look for the max length. 具体来说,检查表的FilePath列并查找最大长度。

也许看看SQLServerCE参数大小限制。

What is the specific maximum length? 具体的最大长度是多少? Is it around 100 chars? 大约100个字符吗? (Guessing based on your provided input example). (根据您提供的输入示例进行猜测)。 The 100 unicode chars also matches with DK Mulligan's answer. 100个Unicode字符也与DK Mulligan的答案匹配。 Looking at SQL ServerCE Paramater Size Property 查看SQL ServerCE参数大小属性

For variable-length data types, the Size property describes the maximum amount of data to send to the server. 对于长度可变的数据类型,Size属性描述了要发送到服务器的最大数据量。 For example, the Size property can be used to limit the amount of data sent to the server for a string value to the first 100 bytes. 例如,Size属性可用于将发送到服务器的字符串值的数据量限制为前100个字节。

For Unicode string data, the Size property refers to the number of characters. 对于Unicode字符串数据,Size属性是指字符数。 The count for strings does not include the terminating character. 字符串的计数不包括终止字符。

Try bumping the size to see if this is the magic number that is truncating your strings. 尝试增大大小以查看这是否是截断字符串的魔数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM