DAO Database

HomeOverviewHow Do IFAQSampleTutorialODBC Driver List

This article explains the role of CDaoDatabase objects in your application. For task-oriented information about using database objects, see the article DAO Database: Using Workspaces and Databases. For an understanding of the DAO database object underlying each MFC CDaoDatabase object, see the following topics in DAO Help:

Topics covered in this article include:

Database: Definition

A DAO database object, represented in MFC by class CDaoDatabase, represents a connection to a database through which you can operate on the data. You can have one or more CDaoDatabase objects active at a time in a given workspace, represented by a CDaoWorkspace object.

For information about database management systems (DBMSs) you can work with, see What Data Sources Can I Access with DAO and ODBC?.

External Databases

Besides using CDaoDatabase to work with Microsoft Jet (.MDB) databases, you can also access external data sources, particularly Open Database Connectivity (ODBC) data sources. For a list of external data sources, see the topic External Data Source: Definition in the article DAO: Working with External Data Sources.

Database Collections

In DAO:

In MFC, access to a workspace’s Databases collection is through member functions of class CDaoWorkspace. Access to a database object’s collections is through member functions of class CDaoDatabase.

Note   DAO collections are not collections in the sense of the MFC collection classes. They are an integral part of DAO.

Note   MFC exposes all of a database’s collections via member functions except for the Recordsets collection. In MFC, you always have an explicit CDaoRecordset object for each recordset you create, and it is up to you to track these objects.

For more information about DAO collections in MFC, see the article DAO Collections. For related information, see the topic "Databases Collection" in DAO Help.

Database Roles

CDaoDatabase allows you to:

Accessing Database Objects

When you open a CDaoRecordset object without specifying an open CDaoDatabase object, MFC implicitly creates a CDaoDatabase object, along with the CDaoWorkspace that contains the database and the underlying DAO database object. You can also create explicit CDaoDatabase objects.

See the article DAO: Accessing Implicit MFC DAO Objects for information on accessing:

Database Persistence

Database objects exist in memory for the life of a database engine session. When that session terminates, the default workspace, the Workspaces collection, the Databases collection in each open workspace, and the database objects in the Databases collection(s) cease to exist (although the databases they represent do persist). These software objects are not stored on disk or in a database. When you begin a new database engine session and want to use the workspaces and databases you used in the last session, you must re-create any explicit workspace objects you need, and reopen any databases you were using in the workspace.

Tip   Use a Windows registry entry to preserve a record of the workspaces and databases you had open during a database engine session.

Further Reading About Databases

For more information about databases in MFC, see the following articles (in recommended reading order):

See Also   DAO: Where Is..., DAO: Database Tasks