CDatabase Class
TOC
Collapse the table of content
Expand the table of content

CDatabase Class

 

Represents a connection to a data source, through which you can operate on the data source.


class CDatabase : public CObject

Name

Description

CDatabase::CDatabase

Constructs a CDatabase object. You must initialize the object by calling OpenEx or Open.

Name

Description

CDatabase::BeginTrans

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.

CDatabase::BindParameters

Allows you to bind parameters before calling CDatabase::ExecuteSQL.

CDatabase::Cancel

Cancels an asynchronous operation or a process from a second thread.

CDatabase::CanTransact

Returns nonzero if the data source supports transactions.

CDatabase::CanUpdate

Returns nonzero if the CDatabase object is updatable (not read-only).

CDatabase::Close

Closes the data source connection.

CDatabase::CommitTrans

Completes a transaction begun by BeginTrans. Commands in the transaction that alter the data source are carried out.

CDatabase::ExecuteSQL

Executes a SQL statement. No data records are returned.

CDatabase::GetBookmarkPersistence

Identifies the operations through which bookmarks persist on recordset objects.

CDatabase::GetConnect

Returns the ODBC connection string used to connect the CDatabase object to a data source.

CDatabase::GetCursorCommitBehavior

Identifies the effect of committing a transaction on an open recordset object.

CDatabase::GetCursorRollbackBehavior

Identifies the effect of rolling back a transaction on an open recordset object.

CDatabase::GetDatabaseName

Returns the name of the database currently in use.

CDatabase::IsOpen

Returns nonzero if the CDatabase object is currently connected to a data source.

CDatabase::OnSetOptions

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.

CDatabase::Open

Establishes a connection to a data source (through an ODBC driver).

CDatabase::OpenEx

Establishes a connection to a data source (through an ODBC driver).

CDatabase::Rollback

Reverses changes made during the current transaction. The data source returns to its previous state, as defined at the BeginTrans call, unaltered.

CDatabase::SetLoginTimeout

Sets the number of seconds after which a data source connection attempt will time out.

CDatabase::SetQueryTimeout

Sets the number of seconds after which database query operations will time out. Affects all subsequent recordset Open, AddNew, Edit, and Delete calls.

Name

Description

CDatabase::m_hdbc

Open Database Connectivity (ODBC) connection handle to a data source. Type HDBC.

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.

System_CAPS_noteNote

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.

Requirements

Header: afxdb.h

Show:
© 2016 Microsoft