MDAC 2.5 SDK - OLE DB Programmer's Reference
Chapter 2: Data Source and Session Objects


 

Session Object Example

The code in this example shows how to create a session object.

/////////////////////////////////////////////////////////////////
// myCreateSession
//
// Create an OLE DB session object from the given data source
// object. The IDBCreateSession interface is mandatory, so this
// is a simple operation.
//
/////////////////////////////////////////////////////////////////
HRESULT   myCreateSession
   (
   IUnknown *           pUnkDataSource,
   IUnknown **          ppUnkSession
   )
{
   HRESULT              hr;
   IDBCreateSession *   pIDBCreateSession = NULL;
   
   //Create a session object from a data source object.
   XCHECK_HR(hr = pUnkDataSource->QueryInterface(
             IID_IDBCreateSession, (void**)&pIDBCreateSession));
   XCHECK_HR(hr = pIDBCreateSession->CreateSession(
             NULL,               // pUnkOuter
             IID_IOpenRowset,    // riid
             ppUnkSession ));    // ppSession
            
CLEANUP:
   if( pIDBCreateSession )
      pIDBCreateSession->Release();
   return hr;
}