Reputation: 4010
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();
}
Upvotes: 1
Views: 2571
Reputation: 1418
I would start with Management Studio -> Tools -> SQL Profiler. Point it at your database and run the upload again. Press pause or stop after you see the error in your app and search for the error message within the trace window. This will give you the SQL that generated this message. If the solution doesn't immediately present itself to you, edit your post with the statement that failed.
Here are some Profiler resources
SQL Server Profiler Step by Step
Upvotes: 0
Reputation: 921
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.
Upvotes: 4