CDatabase Class
Represents a connection to a data source, through which you can operate on the data source.
class CDatabase : public CObject
Members
Public Constructors
Name |
Description |
---|---|
Constructs a CDatabase object. You must initialize the object by calling OpenEx or Open. |
Public Methods
Name |
Description |
---|---|
Starts a "transaction" — a series of reversible calls to the AddNew, Edit, Delete, and Update member functions of class CRecordset — on the connected data source. The data source must support transactions for BeginTrans to have any effect. |
|
Allows you to bind parameters before calling CDatabase::ExecuteSQL. |
|
Cancels an asynchronous operation or a process from a second thread. |
|
Returns nonzero if the data source supports transactions. |
|
Returns nonzero if the CDatabase object is updatable (not read-only). |
|
Closes the data source connection. |
|
Completes a transaction begun by BeginTrans. Commands in the transaction that alter the data source are carried out. |
|
Executes a SQL statement. No data records are returned. |
|
Identifies the operations through which bookmarks persist on recordset objects. |
|
Returns the ODBC connection string used to connect the CDatabase object to a data source. |
|
Identifies the effect of committing a transaction on an open recordset object. |
|
Identifies the effect of rolling back a transaction on an open recordset object. |
|
Returns the name of the database currently in use. |
|
Returns nonzero if the CDatabase object is currently connected to a data source. |
|
Called by the framework to set standard connection options. The default implementation sets the query timeout value. You can establish these options ahead of time by calling SetQueryTimeout. |
|
Establishes a connection to a data source (through an ODBC driver). |
|
Establishes a connection to a data source (through an ODBC driver). |
|
Reverses changes made during the current transaction. The data source returns to its previous state, as defined at the BeginTrans call, unaltered. |
|
Sets the number of seconds after which a data source connection attempt will time out. |
|
Sets the number of seconds after which database query operations will time out. Affects all subsequent recordset Open, AddNew, Edit, and Delete calls. |
Public Data Members
Name |
Description |
---|---|
Open Database Connectivity (ODBC) connection handle to a data source. Type HDBC. |
Remarks
A data source is a specific instance of data hosted by some database management system (DBMS). Examples include Microsoft SQL Server, Microsoft Access, Borland dBASE, and xBASE. You can have one or more CDatabase objects active at a time in your application.
Note
If you are working with the Data Access Objects (DAO) classes rather than the Open Database Connectivity (ODBC) classes, use class CDaoDatabase instead. For more information, see the article Overview: Database Programming.
To use CDatabase, construct a CDatabase object and call its OpenEx member function. This opens a connection. When you then construct CRecordset objects for operating on the connected data source, pass the recordset constructor a pointer to your CDatabase object. When you finish using the connection, call the Close member function and destroy the CDatabase object. Close closes any recordsets you have not closed previously.
For more information about CDatabase, see the articles Data Source (ODBC) and Overview: Database Programming.
Inheritance Hierarchy
CDatabase
Requirements
Header: afxdb.h