Partager via


CDataConnection Class

Manages the connection with the data source.

class CDataConnection

Members

Methods

CDataConnection

Constructor. Instantiates and initializes a CDataConnection object.

Copy

Creates a copy of an existing data connection.

Open

Opens a connection to a data source using an initialization string.

OpenNewSession

Opens a new session on the current connection.

Operators

operator BOOL

Determines whether the current session is open or not.

operator bool

Determines whether the current session is open or not.

operator CDataSource&

Returns a reference to the contained CDataSource object.

operator CDataSource*

Returns a pointer to the contained CDataSource object.

operator CSession&

Returns a reference to the contained CSession object.

operator CSession*

Returns a pointer to the contained CSession object.

Remarks

CDataConnection is a useful class for creating clients because it encapsulates necessary objects (data source and session) and some of the work you need to do when connecting to a data source

Without CDataConnection, you have to create a CDataSource object, call its OpenFromInitializationString method, then create an instance of a CSession object, call its Open method, then create a CCommand object and call its Open* methods.

With CDataConnection, you only need to create a connection object, pass it an initialization string, then use that connection to open commands. If you plan on using your connection to the database repeatedly, it is a good idea to keep the connection open, and CDataConnection provides a convenient way to do that.

Note

If you are creating a database application that needs to handle multiple sessions, you will need to use OpenNewSession.

Requirements

Header: atldbcli.h

See Also

Concepts

OLE DB Consumer Templates (C++)

OLE DB Consumer Templates Reference