Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

database - Local DB throws Byte array truncation to a length of 8000 exception

I'm trying to take a snapshot from a Map control as a WritableBitmap, convert it to a byte array and save it in the local DB. It works fine (I can convert the byte array back to the image) untill I submit the changes to the DB. At this point it throws an exception "Byte array truncation to a length of 8000". I didn't find any documentation about byte array limitation. Does anyone know how to increase the limit of 8000? My byte array is a member of my Model:

private byte[] _locationImage;
[Column]
public byte[] LocationImage
{
   get { return _locationImage; }
   set
   {
      if (_locationImage != value)
      {
         NotifyPropertyChanging("LocationImage");
         _locationImage = value;
         NotifyPropertyChanged("LocationImage");
      }
   }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you look at the SQL Compact docs, you'll see that a binary or varbinary field can be at most 8000 bytes, so that tells me that a byte[] column gets mapped to varbinary. To get it to store data larger than that, you'd need to get the engine to use an image field type. This might be as simple as updating the Column attribute like this (untested):

[Column(DbType="image")]
public byte[] LocationImage { ... }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...