Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Could you please suggest me the best way to save the huge files in the database using c# without putting the load on memory.

At present i m reading the file into BinaryReader and reading it into chunks and sending it to the database. I which takes lots of memory space while execution. So could you please suggest me the best possible way to stream the data database without putting so much pressure on memory.

Thanks in advance
vallab
Posted
Updated 18-Jun-20 12:27pm

vvr15 wrote:
Could you please suggest me the best way to save the huge files in the database using c# without putting the load on memory.


you can't, with ASP.NET, as only one mechanism exists to upload a file in a web page. But with a client app, you could upload the file in chunks, so it doesn't all have to be in memory at once.
 
Share this answer
 
Comments
Vvr15 10-May-10 7:39am    
Can you provide the piece of code. Specially the file reading section in streams.
SQL server can read the file directly from the filesystem if the SP runs under someone with the bulkadmin server privilege. This bulk command worked for us:

update someTable
set FileData = (select * from openrowset(bulk ''' + @filepath + ''', single_blob) as blob)
where id = 1;
 
Share this answer
 
Comments
Maciej Los 19-Jun-20 2:08am    
I doubt that OP is interested in answer after 10 years...
BTW: your code is sql injection vulnerable.

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