I’m developing some application in ASP.NET MVC3 and trying to upload some file in SQL Server 2008, I have the type varbinary(MAX) in DB and I have the code below for uploading it, but I get the error “String or binary data would be truncated . The statement has been terminated” which I believe it’s a data base error, where do you think my problem is? thanks
if (UploadedFile != null)
{
App_MessageAttachment NewAttachment= new App_MessageAttachment { FileName = UploadedFile.FileName, FilteContentType = UploadedFile.ContentType, MessageId = NM.Id, FileData = new byte[UploadedFile.ContentLength] };
UploadedFile.InputStream.Read(NewAttachment.FileData, 0, UploadedFile.ContentLength);
db.App_MessageAttachments.InsertOnSubmit(NewAttachment);
db.SubmitChanges();
}
That is a database error, but it isn’t necessarily associated with the file portion of the insert. Check to make sure that FileName, FileContentType, and MessageId are all short enough to fit within their fields in the database.