Session Objects (OLE DB)

Session objects provide methods for creating commands and rowsets and for creating and modifying tables and indexes. They also define transaction scope and can be used to create transaction objects, which are used to control nested transactions.

The session object cotype is defined as follows. For more information about cotypes, see Conceptual Programming Models in OLE DB.

CoType TSession {
   [mandatory]   interface IGetDataSource;
   [mandatory]   interface IOpenRowset;
   [mandatory]   interface ISessionProperties;
   [optional]    interface IAlterIndex;
   [optional]    interface IAlterTable;
   [optional]    interface IBindResource;
   [optional]    interface IConnectionPointContainer;
   [optional]    interface ICreateRow;
   [optional]    interface IDBCreateCommand;
   [optional]    interface IDBSchemaRowset;
   [optional]    interface IIndexDefinition;
   [optional]    interface ISupportErrorInfo;
   [optional]    interface ITableCreation;
   [optional]    interface ITableDefinition;
   [optional]    interface ITableDefinitionWithConstraints;
   [optional]    interface ITransaction;
   [optional]    interface ITransactionJoin;
   [optional]    interface ITransactionLocal;
   [optional]    interface ITransactionObject;
}

If the session supports ITransactionLocal, the consumer can call ITransactionLocal::StartTransaction to start an explicit transaction. The session is then said to be in manual-commit mode, and any work done in the session must be explicitly committed or aborted. If ITransactionLocal is not supported or if the consumer does not call StartTransaction, the session is said to be in auto-commit mode, and any work done in the session is automatically committed. It cannot be aborted. For more information about transactions, see Transactions.

To create a session, a consumer calls IDBCreateSession::CreateSession on the data source object. A single data source object can support multiple sessions and, therefore, multiple transactions. From a session, the consumer can do the following:

  • Create a command object by calling IDBCreateCommand::CreateCommand. A single session can support multiple commands. Some providers do not support commands.

  • Create a rowset by calling IOpenRowset::OpenRowset. This is equivalent to creating a rowset over a single table and is supported by all providers.

  • Create or modify tables and indexes with ITableDefinition and IIndexDefinition. Although providers are not required to support these interfaces, any provider built over a data store that supports creating and modifying tables and indexes should support them. For simple providers, such as a provider built over an array of data, ITableDefinition might be the only way to create or modify table definitions.

  • Create a schema rowset by calling IDBSchemaRowset::GetRowset, if the provider supports schema rowsets. For more information about schema rowsets, see Appendix B: Schema Rowsets.

This section contains the following topic: