I am trying to insert a image to my online database but on insertion the database closes my connection during the execution. I have tested other insert statements with other tables on the same database and works fine. I have tried changing the database type to varbinary(MAX) and image. Still the same error.
My image is getting saved in a byte []
variable and then inserted with AddWithValue.
Here is my code to convert a signature to a byte []
:
var signatureImage = sig.GetImage();
byte[] bitmapData;
using (var memStream = new MemoryStream())
{
signatureImage.Compress(Bitmap.CompressFormat.Jpeg, 50, memStream);
bitmapData = memStream.ToArray();
}
Here is my code for adding into a parameter for my SQL command:
command.Parameters.AddWithValue("@waiverSigned", user.waiverSigned);
The Error I am getting:
System.Data.SqlClient.SqlException (0x80131904): Server closed the connection.
Environment: Xamarin Android
Let me know if you need anything else.