CDaoWorkspace

A CDaoWorkspace object manages a named, password-protected database session from login to logoff, by a single user. In most cases, you will not need multiple workspaces, and you will not need to create explicit workspace objects; when you open database and recordset objects, they use DAO’s default workspace. However, if needed, you can run multiple sessions at a time by creating additional workspace objects. Each workspace object can contain multiple open database objects in its own Databases collection. In MFC, a workspace is primarily a transaction manager, specifying a set of open databases all in the same “transaction space.”

Note The DAO database classes are distinct from the MFC database classes based on Open Database Connectivity (ODBC). All DAO database class names have a “CDao” prefix. In general, the MFC classes based on DAO are more capable than the MFC classes based on ODBC. The DAO-based classes access data through the Microsoft Jet database engine, including ODBC drivers. They also support Data Definition Language (DDL) operations, such as creating databases and adding tables and fields via the classes, without having to call DAO directly.

Capabilities

Class CDaoWorkspace provides the following:

Security

MFC does not implement the Users and Groups collections in DAO, which are used for security control. If you need those aspects of DAO, you must program them yourself via direct calls to DAO interfaces. For information, see Technical Note 54.

Usage

You can use class CDaoWorkspace to:

Creating a new workspace that does not already exist in the Workspaces collection is described under the Create member function. Workspace objects do not persist in any way between datababase engine sessions. If your application links MFC statically, ending the application uninitializes the database engine. If your application links with MFC dynamically, the database engine is uninitialized when the MFC DLL is unloaded.

Feature Only in Professional and Enterprise Editions   Static linking to MFC is supported only in Visual C++ Professional and Enterprise Editions. For more information, see Visual C++ Editions.

Explicitly opening the default workspace, or opening an existing workspace in the Workspaces collection, is described under the Open member function.

End a workspace session by closing the workspace with the Close member function. Close closes any databases you have not closed previously, rolling back any uncommitted transactions.

Transactions

DAO manages transactions at the workspace level; hence, transactions on a workspace with multiple open databases apply to all of the databases. For example, if two databases have uncommitted updates and you call CommitTrans, all of the updates are committed. If you want to limit transactions to a single database, you need a separate workspace object for it.

Implicit Use of the Default Workspace

MFC uses DAO’s default workspace implicitly under the following circumstances:

Other Operations

Other database operations are also provided, such as repairing a corrupted database or compacting a database.

For more about CDaoWorkspace, see the article DAO Workspace. For information about calling DAO directly and about DAO security, see Technical Note 54. For more about working with ODBC data sources through DAO, see the article DAO External: Working with External Data Sources. For information about the database engine, see the article DAO Workspace: The Database Engine. All articles are in Visual C++ Programmer's Guide. The MFC Database sample DAOVIEW illustrates using CDaoWorkspace.

#include <afxdao.h>   

Class MembersBase ClassHierarchy Chart

Sample   MFC Sample DAOVIEW

See Also   CDaoDatabase, CDaoRecordset, CDaoTableDef, CDaoQueryDef, CDaoException