Udostępnij za pośrednictwem


Connecting to a Data Source

An ODBC data source is a specific set of data, the information required to access that data, and the location of the data source, which can be described using a data-source name. From your program's point of view, the data source includes the data, the DBMS, the network (if any), and ODBC.

To access data provided by a data source, your program must first establish a connection to the data source. All data access is managed through that connection.

Data-source connections are encapsulated by class CDatabase. When a CDatabase object is connected to a data source, you can:

  • Construct recordsets, which select records from tables or queries.

  • Manage transactions, batching updates so all are committed to the data source at once (or the whole transaction is rolled back so the data source is unchanged) — if the data source supports the required level of transactions.

  • Directly execute Structured Query Language (SQL) statements.

When you finish working with a data-source connection, you close the CDatabase object and either destroy it or reuse it for a new connection. For more information about data-source connections, see Data Source (ODBC).

See Also

Concepts

ODBC and MFC