Insert into varbinary(max) failing
Posted on 2011-10-26
I am trying to insert an image and 2 thumbnails into varbinary(max) fields via a stored procedure and I am getting an error returned. If I execute the the SP direct and provide nulls for the fields then the row is created so I suspect the SP and Table are Ok. I also list the byte array sizes when it fails so I can see the buffers have some data, eg.
The c# code is:
SqlCommand objCommand = new SqlCommand();
// Add user id and display order (ints)
objCommand.Parameters.Add("@picTenId", SqlDbType.Int).Value = strId;
objCommand.Parameters.Add("@picOrderId", SqlDbType.Int).Value = "1";
// create and add byte array buffers
byte bufM = new byte;
bufM = new FixedResizeConstraint(620, 410).SaveProcessedImageToByteArray(strImageF);
byte bufT1 = new byte;
bufT1 = new FixedResizeConstraint(200, 132).SaveProcessedImageToByteArray(strImageF);
byte bufT2 = new byte;
bufT2 = new FixedResizeConstraint(116, 77).SaveProcessedImageToByteArray(strImageF);
// run the stored procedure
Int32 lngResult = utlData.Run_Procedure("hex_setPicture", objCommand);
The function adds a final 'result' output parameter to the command object, hopefully to return a new row Id. The function works well with inserts to other tables so I also don't suspect a big problem here.
The function returns -1 which is my error setting.
I'm a bit stumped as I've tried every thing I can think of - any ideas would be gratefully received.