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 ApplicationsNon-.NET programming languages like C++ can use the Win32 Open Database Connectivity(ODBC) APIs to create a connection to the desired database and begin a databasetransaction. Listing 3-2 shows an example.//Connect to <strong>SQL</strong> <strong>Server</strong> through ODBC using DSN "NorthPole"<strong>SQL</strong>Connect(hdbc, TEXT("NorthPole"), <strong>SQL</strong>_NTS, NULL, 0, NULL, 0);//Start a transaction by setting AUTO_COMMIT attribute to OFF<strong>SQL</strong>SetConnectAttr(hdbc, <strong>SQL</strong>_ATTR_AUTOCOMMIT, (<strong>SQL</strong>POINTER)<strong>SQL</strong>_AUTOCOMMIT_OFF,<strong>SQL</strong>_IS_UINTEGER);Listing 3-2:Using C++ to start a transaction on an ODBC connection.When the AUTO_COMMIT attribute is turned OFF on an ODBC connection, the nextT-<strong>SQL</strong> statement starts an explicit transaction. <strong>The</strong> transaction stays active until <strong>SQL</strong>_COMMIT or <strong>SQL</strong>_ROLLBACK is called explicitly using <strong>SQL</strong>EndTran().Step 2: Retrieving the logical path name andtransaction contextBefore accessing a <strong>FILESTREAM</strong> data value, we must retrieve, from <strong>SQL</strong> <strong>Server</strong>, thelogical path to the disk file associated with the <strong>FILESTREAM</strong> data, and the transactioncontext that represents the current database transaction, and then include these values inthe data access request.<strong>FILESTREAM</strong> data values and cellsIn this chapter, the terms <strong>FILESTREAM</strong> cell and <strong>FILESTREAM</strong> data value refer, respectively, to a specificcell in a <strong>FILESTREAM</strong> table (i.e. the intersection <strong>of</strong> a given row and column) and the BLOB data storedin a <strong>FILESTREAM</strong> cell.92

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

Saved successfully!

Ooh no, something went wrong!