DBEngine Object
Description
The DBEngine object is the top level object in the DAO object model.
Remarks
The DBEngine object contains and controls all other objects in the hierarchy of DAO objects. You can't create additional DBEngine objects, and the DBEngine object isn't an element of any collection.
Note When you reference an ODBC data source directly through DAO, it is called an "ODBCDirect workspace." This is to distinguish it from an ODBC data source that you reference indirectly through the Microsoft Jet database engine, using a "Microsoft Jet workspace." Each method of accessing ODBC data requires one of two types of Workspace object; you can set the DefaultType property to choose the default type of Workspace object that you will create from the DBEngine object. The Workspace type and associated data source determines which DAO objects, methods, and properties you can use.
With any type of database or connection, you can:
- Use the Version property to obtain the DAO version number.
- Use the LoginTimeout property to obtain or set the ODBC login timeout, and the RegisterDatabase method to provide ODBC information to the Microsoft Jet database engine. You can use these features the same way, regardless of whether you connect to the ODBC data source through Microsoft Jet or through an ODBCDirect workspace.
- Use the DefaultType property to set the default type of database connection that subsequently created Workspace objects will use — either Microsoft Jet or ODBCDirect.
- Use the DefaultPassword and DefaultUser properties to set the user identification and password for the default Workspace object.
- Use the CreateWorkspace method to create a new Workspace object. You can use optional arguments to override the settings of the DefaultType, DefaultPassword, and DefaultUser properties.
- Use the OpenDatabase method to open a database in the default Workspace, and use the BeginTrans, Commit, and Rollback methods to control transactions on the default Workspace.
- Use the Workspaces collection to reference specific Workspace objects.
- Use the Errors collection to examine data access error details.
Other properties and methods are only available when you use DAO with the Microsoft Jet database engine. You can use them to control the Microsoft Jet database engine, manipulate its properties, and perform tasks on temporary objects that aren't elements of collections. For example, you can:
- Use the CreateDatabase method to create a new Microsoft Jet Database object.
- Use the Idle method to enable the Microsoft Jet database engine to complete any pending tasks.
- Use the CompactDatabase and RepairDatabase methods to maintain database files.
- Use the IniPath and SystemDB properties to specify the location of Microsoft Jet Windows Registry information and the Microsoft Jet workgroup information file, respectively. The SetOption method allows you override windows registry settings for the Microsoft Jet database engine.
After you change the DefaultType and IniPath property settings, only subsequent Workspace objects will reflect these changes.
To refer to a collection that belongs to the DBEngine object, or to refer to a method or property that applies to this object, use this syntax:
[DBEngine.][collection | method | property]
Properties
DefaultType property, DefaultUser, DefaultPassword properties, IniPath property, LoginTimeout property, SystemDB property, Version property.
Methods
BeginTrans, CommitTrans, Rollback methods, CompactDatabase method, CreateDatabase method, CreateWorkspace method, Idle method, OpenConnection method, OpenDatabase method, RegisterDatabase method, RepairDatabase method, SetOption method.
Specifics (Microsoft Access)
Microsoft Access provides a means of manipulating Data Access Objects (DAO) from other applications through Automation. If you are controlling Microsoft Access from another application, such as Visual Basic or Microsoft Excel, you can use the DBEngine property of the Microsoft Access Application object to return a reference to the DBEngine object. All DAO objects and collections are then accessible through the DBEngine object.
Example
This example enumerates the collections of the DBEngine object. See the methods and properties of DBEngine for additional examples.
Sub DBEngineX()
Dim wrkLoop As Workspace
Dim prpLoop As Property
With DBEngine
Debug.Print "DBEngine Properties"
' Enumerate Properties collection of DBEngine,
' trapping for properties whose values are
' invalid in this context.
For Each prpLoop In .Properties
On Error Resume Next
Debug.Print " " & prpLoop.Name & " = " _
& prpLoop
On Error GoTo 0
Next prpLoop
Debug.Print "Workspaces collection of DBEngine"
' Enumerate Workspaces collection of DBEngine.
For Each wrkLoop In .Workspaces
Debug.Print " " & wrkLoop.Name
' Enumerate Properties collection of each
' Workspace object, trapping for properties
' whose values are invalid in this context.
For Each prpLoop In wrkLoop.Properties
On Error Resume Next
Debug.Print " " & prpLoop.Name & _
" = " & prpLoop
On Error GoTo 0
Next prpLoop
Next wrkLoop
End With
End Sub
Example (Microsoft Access)
The following example prints all the properties of the DBEngine object:
Sub EngineProperties()
Dim prp As Property
For Each prp In DBEngine.Properties
Debug.Print prp.Name
Next prp
End Sub