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 SSRSWhen you have added the <strong>FILESTREAM</strong> column, run a SELECT query on the Itemstable; you will see results similar to Listing 6-6. (Of course, the ItemGuid andImageFileName columns might show a different value.)It.. ItemName ImageFileName ItemGuid ItemImage---- -------- ------------------ ----------------- ---------1001 Micros.. C:\..\IMG_5383.jpg 53C15E09-79CC-4.. NULL3001 Dell L.. C:\..\IMG_5384.jpg AFA5D604-68EA-4.. NULL4005 Apple .. C:\..\IMG_5385.jpg B6A6EE8D-7ED6-4.. NULL6009 Amazon.. C:\..\IMG_5386.jpg 6EFF334C-B2C1-4.. NULLListing 6-6:<strong>The</strong> Items table with the <strong>FILESTREAM</strong> column.What we are planning to do in this lab is to run a loop over all the rows in the Itemstable to read the content <strong>of</strong> each image file specified in the ImageFileName column,and then store it in the <strong>FILESTREAM</strong> column, ItemImage. Listing 6-7 creates the storedprocedure that the SSIS package will use to retrieve item information.USE NorthPoleGOCREATE PROCEDURE [dbo].[GetItems]ASSELECT ItemIDFROM Items ;Listing 6-7:Creating a stored procedure to retrieve the ItemID column <strong>of</strong> all the rows.<strong>The</strong> above stored procedure returns the ItemID <strong>of</strong> all the rows to be processed. <strong>The</strong>SSIS package will loop through each row returned by this procedure and execute the<strong>FILESTREAM</strong>-related code to load the images into the <strong>FILESTREAM</strong> column <strong>of</strong> the table.All <strong>FILESTREAM</strong> operations should take place within the context <strong>of</strong> a <strong>SQL</strong> <strong>Server</strong>transaction. You might want to do it in one <strong>of</strong> the two ways illustrated below.233

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

Saved successfully!

Ooh no, something went wrong!