17.07.2015 Views

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5: <strong>FILESTREAM</strong> with ASP.NET and SilverlightSetting up the dataFirst, we'll set up the table and data required for this lab. Create a table in the NorthPoledatabase to store the video files using the T-<strong>SQL</strong> code shown in Listing 5-21.CREATE TABLE Videos(VideoID UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE,VideoName VARCHAR(100),VideoData VARBINARY(MAX) <strong>FILESTREAM</strong>)Listing 5-21:Creating a table to hold the video data.Now, we'll add some videos to the table. For this demo, I will use the sample video filethat comes with the Windows 7 operating system. Listing 5-22 loads a video file intothe table we just created. Make sure that you change the location <strong>of</strong> the file to pointto a .wmv file that exists on the local computer.-- Insert the data into the tableINSERT INTO Videos (VideoID, VideoName, VideoData)SELECT NEWID(), 'Windows7 Sample Video', CAST(bulkcolumnAS VARBINARY(MAX))FROM OPENROWSET(BULK'C:\Users\Public\Videos\Sample Videos\Wildlife.wmv',SINGLE_BLOB ) AS xListing 5-22:Loading a video into the table.Next, create a stored procedure that returns the logical path name <strong>of</strong> the <strong>FILESTREAM</strong>column, along with the <strong>FILESTREAM</strong> transaction context (Listing 5-23).217

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!