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• FileAccess – This parameter specifies the required file access mode. <strong>The</strong> possiblevalues are:• FileAccess.Read – Opens the <strong>FILESTREAM</strong> data file for reading. <strong>The</strong> file pointeris placed at the beginning <strong>of</strong> the file.• FileAccess.Write – Opens the <strong>FILESTREAM</strong> data file for writing.• FileAccess.ReadWrite – Opens the <strong>FILESTREAM</strong> data file for reading andwriting. <strong>The</strong> file pointer is placed at the beginning <strong>of</strong> the file. You can use theSeek() method to move the file pointer to specific locations in the file and makepartial updates, or to move to the end <strong>of</strong> the file to append content.SqlFileStream provides another version <strong>of</strong> the constructor that gives morecontrol over the <strong>FILESTREAM</strong> data file being opened. Listing 3-35 shows an examplethat demonstrates the advanced SqlFileStream constructor.// Open and read file using SqlFileStream ClassSqlFileStream fs = new SqlFileStream(filePath, txContext, FileAccess.Read,FileOptions.SequentialScan, 0);Listing 3-35:Using the advanced <strong>FILESTREAM</strong> constructor.This version <strong>of</strong> the SqlFileStream constructor allows you to specify more optionswhen opening the <strong>FILESTREAM</strong> data file. <strong>The</strong> additional parameters enable you tooptimize the <strong>FILESTREAM</strong> operations.<strong>The</strong> first three parameters are the same as for the basic <strong>FILESTREAM</strong> constructor whichwe discussed earlier. <strong>The</strong> FileOptions parameter enables you to specify additional flagsthat inform the system about your intended file access pattern and optimize the operationsaccordingly. For example, Listing 3-35, above, tells the system that you intend to usethe file sequentially; the system uses this information to optimize <strong>FILESTREAM</strong> accessbecause it knows in advance that you will not move the file pointer backwards or jumpinto a random location in the file.124

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

Saved successfully!

Ooh no, something went wrong!