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 6: <strong>FILESTREAM</strong> with SSIS and SSRS1. Start a <strong>SQL</strong> <strong>Server</strong> transaction at the beginning, process all the rows and commit.2. Start a <strong>SQL</strong> <strong>Server</strong> transaction before processing each row and commit when thegiven row is processed.We will take Option 2 for this lab because, with this approach, locks are placed on eachrow only for a minimal period <strong>of</strong> time. A row will be locked only when the processingstarts and the lock will be released as soon as the given row is processed.To load each image file into the <strong>FILESTREAM</strong> column, we will need the pieces <strong>of</strong>information below:• the <strong>FILESTREAM</strong> transaction context• the <strong>FILESTREAM</strong> logical path (the PathName() value)• the name and location <strong>of</strong> the image file on the disk (to be loaded into the <strong>FILESTREAM</strong>column).We'll create another stored procedure that accepts the ItemID and returns the aboveinformation. Listing 6-8 shows how to create the stored procedure.USE [NorthPole]GOCREATE PROCEDURE [dbo].[GetItemInfo] ( @ItemID INT )AS-- ------------------------------------------------------------------- If the <strong>FILESTREAM</strong> column is NULL, we cannot retrieve PathName().-- In such a case, we need to use a dummy value-- -----------------------------------------------------------------UPDATE dbo.itemsSET ItemImage = 0xWHERE ItemID = @ItemIDAND ItemImage IS NULL234

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

Saved successfully!

Ooh no, something went wrong!