Question Saving Video files in Database

arashroshan

Member
Joined
Jul 9, 2011
Messages
10
Programming Experience
5-10
Hi
i want to know if it is possible to save a video file in database or not ?

thanks
 
Pretty much all databases have a data type dedicated to binary data. For example, SQL Server has the 'varbinary' data type.

When sending data to such a column using ADO.NET, you would work with Byte arrays in code. To get a Byte array from a file you can do this:
Dim data As Byte() = IO.File.ReadAllBytes(filePath)
While it's always a good idea to use parameters to insert variables into databases, it is absolutely essential when working with binary data. There's no way to represent a Byte array in a literal String so you have no choice but to use a parameter. To learn how to do that, follow the Blog link in my signature and check out my post on ADO.NET Parameters.

Having said all that, it's generally not considered to be a good idea to store large amounts of binary data in a database. It makes the database grow very large very quickly. It is often considered a better option to store a file path in the database and store the file separately on a file share or the like.

Some databases give you the best of both worlds. Access 2010 has the Attachment data type where you give the data to the database and it stores it externally itself. Unfortunately, I'm not aware of any way to work with that data type in ADO.NET at this stage.

SQL Server also has a feature called FILESTREAM that you can enable or disable on an instance, including SQL Server Express. You then interact with the database in exactly the same way as you normally would, but it stores 'varbinary' values external to the database itself. It's all transparent to the user, so you don't even have to think about it once FILESTREAM has been enabled.
 
You call IO.File.ReadAllBytes to read a file into a Byte array. What do you suspect you would call to write a Byte array to a file? With a bit of logic and intuition you should be able to answer that yourself.
 
I know . but when i convert a video to byte array , i want to play it as well !!? and i know it is not possible to play a byte array with windows media player .
 
So, the colours in post #4 didn't give any clue at all, or did you not actually look at them? I would think that, if File.ReadAllBytes reads a file into a Byte array, logic would suggest that File.WriteAllBytes writes a Byte array to a file.
 
Back
Top