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 3: Accessing <strong>FILESTREAM</strong> Data from Client Applications<strong>The</strong> client application can then pass this value to the <strong>FILESTREAM</strong> API method callto open the NTFS data file represented by the logical identifier returned by thePathName() function.To illustrate this point, let's return to the example we first saw in Chapter 2, and create anew <strong>FILESTREAM</strong>-enabled database (Listing 3-26).CREATE DATABASE NorthPole ONPRIMARY (NAME = NorthPoleDB,FILENAME = 'C:\<strong>Art</strong>OfFS\Demos\Chapter3\NorthPoleDB.mdf'), FILEGROUP NorthPoleFS CONTAINS <strong>FILESTREAM</strong>(NAME = NorthPole_fs,FILENAME = 'C:\<strong>Art</strong>OfFS\Demos\Chapter3\'NorthPole_fs')LOG ON (NAME = NorthPole_log,FILENAME = 'C:\<strong>Art</strong>OfFS\Demos\Chapter3\NorthPole_log.ldf')Listing 3-26:Creating a <strong>FILESTREAM</strong>-enabled database.In Listing 3-27, we create a table with a <strong>FILESTREAM</strong> column and insert some data.-- Create "Items" tableCREATE TABLE [dbo].[Items]([ItemID] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE,[ItemNumber] VARCHAR(20),[ItemDescription] VARCHAR(50),[ItemImage] VARBINARY(MAX) <strong>FILESTREAM</strong> NULL)GO-- Insert the data to the tableINSERT INTO Items (ItemID, ItemNumber, ItemDescription, ItemImage)SELECTNEWID(), 'MS1001', 'Micros<strong>of</strong>t Mouse',CAST(bulkcolumn AS VARBINARY(MAX))FROM OPENROWSET(BULK 'C:\temp\Micros<strong>of</strong>tMouse.jpg', SINGLE_BLOB) AS xListing 3-27:Creating a table with a <strong>FILESTREAM</strong> column and populating it with sample data.116

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

Saved successfully!

Ooh no, something went wrong!