Click here to Skip to main content
15,896,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in c# SqlDbType.VarBinary maximum size=8000 for parameter;

how do i insert a 450mb file?

C#
byte[] Myfile=.....;

Myquery= "insert into Table1(VarBinMaxfile,name) values(@file,"name1");

cmd.Parameters.add(@file,SqlDbType.VarBinary,8000).value=Myfile;
Posted
Updated 8-Apr-13 11:10am
v2
Comments
fjdiewornncalwe 8-Apr-13 16:47pm    
If you feel the need to insert something that large into the database, you may wish to revisit your architecture. Perhaps a better solution in this type of situation is to store a path to a document repository folder where you can just store the file on disk instead.
scorpzonex 9-Apr-13 4:38am    
in my case storing files in disk is not an option.thank you.

1 solution

Try reading the documentation on the TSQL varbinary type[^] next time.

The field can be defined with a number, from 1 to 8000, or with max, which can be up to 2^31-1 bytes, or 2,147,483,647 bytes.

What you use in your code depends entirely on how the column is defined in your database.
 
Share this answer
 
Comments
fjdiewornncalwe 8-Apr-13 16:46pm    
5.
Maciej Los 8-Apr-13 17:12pm    
Agree, +5!
scorpzonex 9-Apr-13 4:03am    
database field is [varbinary(MAX)]
but the parameter is SqlDbType.VarBinary;
can this SqlDbType.VarBinary be more than 8000?
and how do i define it?
Dave Kreskowiak 9-Apr-13 8:06am    
Instead of 8000, you specify -1 for a VarBinary(MAX).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900