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<strong>The</strong> default location is C:\Program Files\Micros<strong>of</strong>t <strong>SQL</strong> <strong>Server</strong>\100\SDK\Include, but you might find it in a different location, depending upon where youinstalled <strong>SQL</strong> <strong>Server</strong> 2008.<strong>The</strong> code snippet in Listing 3-36 shows an example that opens a <strong>FILESTREAM</strong> data fileusing the OpenSqlFilestream API function.//Get a handle to the <strong>FILESTREAM</strong> data using OpenSqlFileStream APIHANDLE srcHandle = INVALID_HANDLE_VALUE;srcHandle = OpenSqlFilestream ( dstFilePath, <strong>SQL</strong>_<strong>FILESTREAM</strong>_READ, 0,transactionToken,cbTransactionToken, 0);Listing 3-36:Opening a <strong>FILESTREAM</strong> data file for READ access with C++ using Win32 APIOpenSqlFileStream().<strong>The</strong> first argument (dstFilePath) is the logical path to the <strong>FILESTREAM</strong> data file,retrieved by a call to the PathName() function on the <strong>FILESTREAM</strong> column. <strong>The</strong> secondargument specifies the file access level required. This argument can take one <strong>of</strong> the valueslisted below.• <strong>SQL</strong>_<strong>FILESTREAM</strong>_READ – Opens the <strong>FILESTREAM</strong> data file for reading. <strong>The</strong> filepointer is placed at the beginning <strong>of</strong> the file.• <strong>SQL</strong>_<strong>FILESTREAM</strong>_WRITE – Opens the <strong>FILESTREAM</strong> data file for writing. <strong>The</strong> filepointer is placed at the beginning <strong>of</strong> the file. A write operation will overwrite theexisting content in the file.• <strong>SQL</strong>_<strong>FILESTREAM</strong>_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 the Seek()method to move the file pointer to specific locations in the file and make partialupdates, or to move to the end <strong>of</strong> the file to append content.127

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

Saved successfully!

Ooh no, something went wrong!