Home | Overview | How Do I | FAQ | Sample | Tutorial | ODBC Driver List
This article explains how to use CDaoWorkspace and CDaoDatabase objects. Topics covered include:
In the majority of data access applications, you work less at the workspace level than at the database or even recordset level. It might seem the normal thing to construct an explicit CDaoWorkspace object, then from it construct a CDaoDatabase object and from that construct CDaoRecordset, CDaoQueryDef, and CDaoTableDef objects. But the more typical approach is one of the following:
Note This is inefficient if you are continually opening and closing the same database. In that case, create an explicit CDaoDatabase object and use it for the life of your application.
The primary action taken on a workspace object that might be called typical is to use the object for transactions against one or more databases. The transaction commands in MFC are members of class CDaoWorkspace.
To access transaction commands in the most typical case, you can use the implicit workspace that MFC creates behind CDaoDatabase and CDaoRecordset objects (one implicit workspace for multiple objects). To issue transaction commands, such as BeginTrans, CommitTrans, or Rollback, you can choose to call those member functions of CDaoWorkspace through the pointer stored in your CDaoRecordset or CDaoDatabase object. For details about accessing such pointers, see the article DAO: Accessing Implicit MFC DAO Objects.
For example, from a recordset object, you might call:
// prs is a pointer to an already opened
// CDaoRecordset object
prs->m_pDatabase->m_pWorkspace->BeginTrans( );
...
The typical scenario is not enough in some fairly rare cases. For a discussion of when you might need an explicit CDaoWorkspace object, see the article DAO Workspace.
See Also DAO: Where Is..., DAO Workspace: Managing Transactions, DAO Workspace, DAO Database, DAO: Creating, Opening, and Closing DAO Objects