As we all know that we can store different format files in SQL Server in the form of data rows but most of the time it is hard for us to find a working demo on how to store audio/video file in SQL Server 2005 database.
I have created a demo .NET app that we’ll use during our demo to import and export files from SQL Server 2005. In fact we’ll use .NET FileStream & Byte arrays in our sample app to see how import and export of file happens in SQL Server 2005.
For storing files in form of data in SQL Server 2005, we’ll use VarBinary datatype columns.
Here is the code and code guidelines that you should follow to run this demo
Code - Refer to SQL_File_Import_Export.Zip
Code Guidelines –
1. First, create a table MyBlobTable in your database,Create Table MyBlobTable (id int identity(1,1), blob_description varchar(100),blob_data varbinary (max))
2. Open SQL2005BLOB.sln solution file in .NET IDE.2.Now change connection string in sConnectionString variable,change it to point to your local SQL Server/DB.2. In ImportBLOB() sub routine, change FS (File Stream) object path to pointto your local media file.3. In RetrieveBLOB() sub routine, change MediaFile object path to yourdesired output path, this will be the path where your media file will begenerated from your varbinary column data.4. As you know from step 1 that every entry will update identity columnvalue, therefore you need to update your query statement with id column valueaccordingly (Dim da As New SqlDataAdapter _("Select blob_data From MyBLOBTable where id = 4", cn))