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 ApplicationsSqlFileStream Class Reference<strong>The</strong> SqlFileStream class represents the <strong>FILESTREAM</strong> data file associated with theBLOB data stored in a <strong>FILESTREAM</strong> cell. This class exposes the BLOB as a sequence<strong>of</strong> bytes.SqlFileStream is derived from System.IO.Stream and resides in the System.Data.Sqltypes namespace. To use the SqlFileStream class, you need a referenceto assembly System.Data in System.Data.dll. (SqlFileStream was added to theFramework with.NET Framework 3.5 SP 1 or later, which also includes 2.0 SP 2 and3.0 SP 2.)Instantiating a SqlFileStream objectSqlFileStream provides two constructors that you can use to instantiate an object withdifferent levels <strong>of</strong> control over the file being accessed. We have seen an example <strong>of</strong> thebasic constructor earlier in this chapter. Listing 3-34 shows the simple constructor that wesaw earlier.// Open and read file using SqlFileStream ClassSqlFileStream fs = new SqlFileStream(filePath, txContext, FileAccess.Read);Listing 3-34:C# code that opens a <strong>FILESTREAM</strong> data file for read access.• filePath – This is the logical path to the physical file associated with the<strong>FILESTREAM</strong> data value. <strong>The</strong> logical path is retrieved by a call to the PathName()function on the <strong>FILESTREAM</strong> column on the specific row in the table.• txContext – This is the <strong>FILESTREAM</strong> transaction context associated with the currenttransaction. Note that you need an active transaction even to read <strong>FILESTREAM</strong> datawhen accessing through I/O streaming.123

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

Saved successfully!

Ooh no, something went wrong!