Size limit for sql_variant exceeds

I am trying to save an image from file upload control to a database

public Byte[] bytes;
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
bytes = br.ReadBytes((Int32)fs.Length);
SqlDataSource2.Update();

protected void SqlDataSource2_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
   e.Command.Parameters["@project_file"].Value = bytes;
}

In my database project_fileis set varbinary(MAX),

but he gives an error

The parameter "@project_file" exceeds the size limit for the sql_variant data type.

Please suggest some solution.

+5
source share
3 answers

This is a quote from MSDN in binary and varbinary :

. n 1 8 000. , 2 ^ 31-1 . - + 2 . , 0 . ANSI SQL varbinary - .

varbinary(MAX) ~ 2 .

:

. SqlDbType.

e.Command.Parameters["@project_file"].SqlDbType = SqlDbType.VarBinary

, Size.

+7

, sql "SQL_Variant".

DbType:

e.Command.Parameters["@project_file"].SqlDbType = SqlDbType.Image
e.Command.Parameters["@project_file"].Value = bytes;
+1

SQL_VARIANT #. :

Dim binaryStream As SqlBinary

. http://msdn.microsoft.com/en-us/library/a1904w6t(VS.80).aspx

P.S. Image Blob, . varbinary (MAX).

Image vs Varbinary (max):

0 2 ^ 31-1 (2 147 483 647) .

varbinary [(n | max)] (the maximum storage size is 2 ^ 31-1 bytes). Variable length binary data. n can be a value from 1 to 8000. max indicates that the maximum storage size is 2 ^ 31-1 bytes. Storage size is the actual length of the entered data + 2 bytes. Entered data can be 0 bytes long. The ANSI SQL synonym for varbinary changes binary.

0
source

All Articles