The type of my database column is varbinary(max), (sql server 2008).
Linq to Sql Classes (vs 2010, fx4) has generated this code for me:
[global::System.Data.Linq.Mapping.ColumnAttribute
(Storage="_Raw", DbType="VarBinary(MAX)", UpdateCheck=UpdateCheck.Never)]
public System.Data.Linq.Binary Raw
{
get
{
return this._Raw;
}
...
I want to insert a 1.5 Mb bitmap file like so:
var fi = new FileInfo(@"c:\whatever.bmp");
var fs = fi.OpenRead();
var newImage = new Image();
//var buffer = new byte[fs.Length];
//fs.Read(buffer, 0, (int)fs.Length);
//newImage.Raw = buffer;
var buffer = new byte[4000];
fs.Read(buffer, 0, 4000);
newImage.Raw = buffer;
using (var dc = new MyDataContext())
{
dc.Images.InsertOnSubmit(newImage);
dc.SubmitChanges();
}
fs.Dispose();
The lines I've commented out are what I want the code to be, but they throw an exception at the SubmitChanges call. The lines underneath do work ok. But if I increase the buffer size to 4001, I get the same exception. I'm going to need to have an fs.Length of more like 1,500,000.
The exception message is "String or binary data would be truncated." Can anyone explain this error and show me how to get it working?