| title | CDataConnection Class | Microsoft Docs | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ms.custom | ||||||||||||||
| ms.date | 11/04/2016 | |||||||||||||
| ms.reviewer | ||||||||||||||
| ms.suite | ||||||||||||||
| ms.technology |
|
|||||||||||||
| ms.tgt_pltfrm | ||||||||||||||
| ms.topic | article | |||||||||||||
| f1_keywords |
|
|||||||||||||
| dev_langs |
|
|||||||||||||
| helpviewer_keywords |
|
|||||||||||||
| ms.assetid | 77432d85-4e20-49ec-a0b0-142137828471 | |||||||||||||
| caps.latest.revision | 13 | |||||||||||||
| author | mikeblome | |||||||||||||
| ms.author | mblome | |||||||||||||
| manager | ghogen | |||||||||||||
| translation.priority.ht |
|
Manages the connection with the data source.
class CDataConnection
| 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. |
| 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. |
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.
Header: atldbcli.h
OLE DB Consumer Templates
OLE DB Consumer Templates Reference