Share via


DAO Database

OverviewHow Do IFAQSampleODBC Driver List

This article explains the role of 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:

  • Database Object

  • Databases Collection

Topics covered in this article include:

  • Database: Definition

  • External databases

  • Database collections

  • Database roles

  • Accessing database objects

  • Database persistence

  • Further reading about databases

Database: Definition

A DAO database object, represented in MFC by class , 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 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 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:

  • Each workspace object contains a collection of open database objects, called the Databases collection.

  • Each DAO database objects contains collections of tabledefs, querydefs, recordsets, and relations.

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

****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 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

allows you to:

  • Create new Microsoft Jet (.MDB) database files.

  • Store tabledef objects that you can use to manipulate the structure of the database’s tables.

  • Store querydef objects so you can reuse the queries they represent later.

  • View and manipulate data in the database’s tables.

  • Work with data in local or remote databases.

  • Work with the database’s collections.

Accessing Database Objects

When you open a object without specifying an open object, MFC implicitly creates a CDaoDatabase object, along with the 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:

  • The CDaoDatabase object associated with a CDaoRecordset object.

  • The CDaoWorkspace object associated with a CDaoDatabase object.

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