Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
We have web application which is store and retrieve files from database, we using sql server for store data. i want to store file like video file which size almost above 2 gb, when i read using filestrema and store i bytes , it show error like
"Arithmetic operation resulted in an overflow"


bcz byte support maximum 255 length.

What I have tried:

This is my code which i used to read in file stream and pass to bytes
VB
Dim fs As System.IO.FileStream
fs = File.Open(fpath, FileMode.Open, FileAccess.Read, FileShare.None)
Dim filelen As Long = fs.Length
Dim buffer As Byte()  
fs.Read(buffer, 0, filelen) ' Here i get error , bcz of byte support 255 
fs.Close()


I tried chunks to read big files, but how to store in table, bcz table support binary value to store in table

Any way to store large size in file stream table ?

Thanks and regards
Aravind
Posted
Updated 16-Nov-21 22:20pm
Comments
CHill60 11-Nov-21 5:52am    
Most common advice I've seen is "Don't" - store the video file on the file server and just store a link to it on the SQL database
Aravindba 11-Nov-21 6:26am    
yes , if backup database, how file also include in that backup ?
CHill60 11-Nov-21 7:01am    
You would need a separate backup for the file system
Aravindba 17-Nov-21 0:04am    
it difficult to change flow, bcz already live at customer place , so cant store file in folder and its path in sql server , so pls suggest any other way.
Richard Deeming 11-Nov-21 6:21am    
I don't believe you're getting that error message from that code. The line: Dim buffer As Byte() does not initialize the variable to anything, so you'll actually get an ArgumentNullException on the following line, since you're passing Nothing as the buffer to receive the data.

But as CHill60 said, don't store large files in SQL databases. Store them on disk, and store the path in the database.

1 solution

Your question is not really about how to store these files in SQL (However, here is the documentation on that Binary Large Object (Blob) Data (SQL Server) - SQL Server | Microsoft Docs[^] ).

It's about how to manipulate those images in C# in order to read/write them to the database.

So, you could use Filestream
Create Client Applications for FILESTREAM Data - SQL Server | Microsoft Docs[^]
Using SqlFileStream with C# to Access SQL Server FILESTREAM Data | Tallan[^]

Or you could store the images in the file system directly and just store paths on your database. Your "live client" will thank you for the improved performance
 
Share this answer
 

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