Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there..

I have a stored procedure that I am using to store varbinary data, so if the file is small almost 50mb to 150mb it works fine, but the problem when I try to store bigger than 300 mb, it doesn't work and shows message says:
Quote:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

The stored procedure is:
SQL
PROCEDURE AddData
    @FileContent varbinary(MAX)
AS
    INSERT INTO [AttachmentTable] 
    (
        [ContentFile]
    )
    VALUES 
    (
        @FileContent
    )

The parameter is send from c# as byte[]

What can I do to solve this problem?

Thanks in advance.

What I have tried:

I searched many websites but no answers.
Posted
Updated 7-May-20 6:12am
v3
Comments
phil.o 5-May-20 20:22pm    
Please, don't shout :)

1 solution

Usually, it is not recommended to store files, especially large ones, in your database. Databases are not optimized to store huge binary files. Instead, you shoud store the path to the file in the database, and leave the file itself to the regular file system.
This is in fact a very common questionning, here are a couple of links relative to that matter:
database - Storing Images in DB - Yea or Nay? - Stack Overflow[^]
File System vs. Database - dzone[^]
 
Share this answer
 
Comments
Jassom 5-May-20 21:18pm    
thank you for reply.

The server is located on the same client machine so I don't worry about database size .. etc. also the reason of why I want to store files in database is becuase the data is sensitive and I don't want others see them outside database.
MadMyche 5-May-20 22:30pm    
Have you used any of the analytic tools in SQL Server or the Performance Monitor in Windows to see what is happening with memory & CPU usage?
Jassom 6-May-20 16:58pm    
Thank you for reply.
I use the Performance Monitor in Windows to see what is happening, CPU performance is working normal, memory gets full about 95% when storing files up to 250MB.
MadMyche 6-May-20 19:12pm    
Well, that about answers your question: your system is running out of resources when you try to do this.
The resolution is simple: Don't do. Encrypt the file and save it as a file, and have a reference in your table for it
Dave Kreskowiak 5-May-20 22:40pm    
Then encrypt the files and decrypt them when you need them.

Really, Storing a 300MB file in the database is a bad idea no matter how you look at it.

Take a look at the following and see what it can do for you.
Binary Large Object (Blob) Data (SQL Server) - SQL Server | Microsoft Docs[^]

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