DAO supports two different database environments or workspaces.
Use the Microsoft Jet workspace when you open a Microsoft Jet database (.mdb file) or other desktop ISAM database, or when you need to take advantage of Microsoft Jet's unique features, such as the ability to join data from different database formats.
The ODBCDirect workspace provides an alternative when you only need to execute queries or stored procedures against a back-end server, such as Microsoft SQL Server, or when your client application needs the specific capabilities of ODBC, such as batch updates or asynchronous query execution.
DAO Objects
There are 17 different DAO object types. You can declare new DAO object variables for any of the object types.
For example, the following Visual C++ code creates object variables for a CdbDatabase object, a dynaset-type CdbRecordset object, and a CdbField object:
CdbDBEngine eng;
CdbDatabase dbs;
CdbRecordset rst;
CdbField fld;
//
dbs = eng.OpenDatabase("Biblio.mdb");
rst = dbs.OpenRecordset("Authors", dbOpenDynaset);
fld = rst.Fields["Au_ID"];
DAO Collections
Each DAO object type other than CdbDBEngine also has a corresponding collection. A collection includes all the existing objects of that type. For example, the Recordsets collection contains all open CdbRecordset objects. Each collection is "owned" by another object at the next higher level in the hierarchy. A CdbDatabase object "owns" a Recordsets collection. Except for the CdbConnection and CdbError objects, every DAO object has a Properties collection.
Most DAO objects have default collections. For example, the default collection of a CdbRecordset object is the Fields collection. You can simplify your code by taking advantage of these defaults. For example, the following code returns the PubID field in the current record:
CdbField fld = rstExample["PubID"];
CdbDBEngine and CdbWorkspace Objects
All DAO objects are derived from the CdbDBEngine object. You can set the DefaultType property on the CdbDBEngine object to determine the workspace type (Microsoft Jet or ODBCDirect) to create on subsequent CreateWorkspace method calls, or you can override this property with the Type argument in the CreateWorkspace method itself. When your application creates a workspace, the appropriate library — the Microsoft Jet database engine or ODBC — is loaded into memory at that time.
You can open additional CdbWorkspace objects as needed. Each CdbWorkspace object has a user ID and password associated with it.