Our application stores image binary data in a table called Blob. I'm trying to update the Blob field, and running into the above error. Here's the code I'm using (C#):
command.CommandText = @"
SET Binary = @Binary
WHERE BlobGuid = @BlobGuid";
command.Parameters.Add("@BlobGuid", System.Data.SqlDbType.UniqueIdentifier).Value = blobGuid;
command.Parameters.Add("@Binary", System.Data.SqlDbType.Image).Value = dataBuffer;
This throws the error "String or binary data would be truncated. The statement has been terminated." While I understand that this means that I'm trying to put data into a field that doesn't have room for it, I can't see how in this case. dataBuffer.length (dataBuffer is a byte array) in the sample is 780831, which is the size of the image file, and the Image field holds 2^31 - 1 bytes, which is more than enough. What's more, I don't have any trouble adding the file to a new Blob record.
The initial code used System.Data.SqlDbType.VarBinary instead of Image. I first tried System.Data.SqlDbtype.VarBinary, dataBuffer.Length
, with the idea that VarBinary's default size was the old-fashioned 8.000 bytes, but that had the same problem.
Can anyone enlighten me?
An unforeseen consequence of the information revolution has been the exponential propagation of human error.