Create a DBOBJECT structure describing how the BLOB column should be accessed. Set the dwFlag element of the DBOBJECT structure to STGM_READ and set the iid element to IID_ISequentialStream (the interface to be exposed).

Set the properties in the DBPROPSET_ROWSET property group so the rowset is updatable.

Create a set of bindings (one of each column) by using an array of DBBINDING structures. Set the wType element in the DBBINDING structure to DBTYPE_IUNKNOWN, and the pObject element to point to the DBOBJECT structure you created.

Create an accessor using the binding information in the DBBINDINGS array of structures.

Call GetNextRows to fetch next rows into the rowset. Call GetData to read the data from the rowset.

To set the data, create a storage object containing the data (and also the length indicator), and then call IRowsetChange::SetData (or IRowsetChange::InsertRow) with the accessor that binds the BLOB column.

The complete sample code is in the file WorkingWithBLOBs.cpp. You can download an archive containing the sample from the SQL Server Downloads page on MSDN.

This sample was developed using Microsoft Visual C++ 2005.

Security Note:

When possible, use Windows Authentication. If Windows Authentication is not available, prompt users to enter their credentials at run time. Avoid storing credentials in a file. If you must persist credentials, you should encrypt them with the Win32 crypto API.