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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3: Accessing <strong>FILESTREAM</strong> Data from Client Applications//Get a handle to the <strong>FILESTREAM</strong> data using OpenSqlFileStream API<strong>SQL</strong>CHAR transactionToken[32];<strong>SQL</strong>INTEGER cbTransactionToken = size<strong>of</strong>(transactionToken);HANDLE srcHandle = INVALID_HANDLE_VALUE;srcHandle = OpenSqlFilestream (dstFilePath, <strong>SQL</strong>_<strong>FILESTREAM</strong>_READ,<strong>SQL</strong>_<strong>FILESTREAM</strong>_OPEN_NONE , transactionToken,cbTransactionToken, 0);Listing 3-7:Using C++ to open a <strong>FILESTREAM</strong> data file for read access.<strong>The</strong> first parameter is the logical path to the <strong>FILESTREAM</strong> data file obtained from a callto the PathName() function. <strong>The</strong> second argument specifies file access mode. It can beone <strong>of</strong> <strong>SQL</strong>_<strong>FILESTREAM</strong>_READ, <strong>SQL</strong>_<strong>FILESTREAM</strong>_WRITE, or <strong>SQL</strong>_<strong>FILESTREAM</strong>_READWRITE (for read, write, and read/write operations respectively).<strong>The</strong> third parameter allows you to specify the file attributes and flags. <strong>The</strong>se areadditional hints that tell the system about the usage pattern, and the system will usethis information to optimize caching and performance. In Listing 3-7 we have set it to<strong>SQL</strong>_<strong>FILESTREAM</strong>_OPEN_NONE which indicates that the file needs to be opened with nospecific flags.<strong>The</strong> fourth argument is the transaction context we retrieved, and the fifth specifies thesize (in bytes) <strong>of</strong> the transaction context buffer.<strong>The</strong> last argument allows you to specify the initial allocation size <strong>of</strong> the data file in bytes;this is ignored when the file is opened for read operation.See OpenSqlFilestream API Reference, later in this chapter, for a detailed discussion <strong>of</strong> thisAPI function.97

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

Saved successfully!

Ooh no, something went wrong!