简体   繁体   中英

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. 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

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.

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. Specifically, check the FilePath column of your table and look for the max length.

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

What is the specific maximum length? Is it around 100 chars? (Guessing based on your provided input example). The 100 unicode chars also matches with DK Mulligan's answer. Looking at SQL ServerCE Paramater Size Property

For variable-length data types, the Size property describes the maximum amount of data to send to the server. 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.

For Unicode string data, the Size property refers to the number of characters. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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