You use the Database object and its methods and properties to manipulate an open database. In any type of database, you can:
|?||Use the Execute method to run an action query.|
|?||Set the Connect property to establish a connection to an ODBC data source.|
|?||Set the QueryTimeout property to limit the length of time to wait for a query to execute against an ODBC data source.|
|?||Use the RecordsAffected property to determine how many records were changed by an action query.|
|?||Use the OpenRecordset method to execute a select query and create a Recordset object.|
|?||Use the Version property to determine which version of a database engine created the database.|
With a Microsoft Jet database (.mdb file), you can also use other methods, properties, and collections to manipulate a Database object, as well as create, modify, or get information about its tables, queries, and relationships. For example, you can:
|?||Use the CreateTableDef and CreateRelation methods to create tables and relations, respectively.|
|?||Use the CreateProperty method to define new Database properties.|
|?||Use the CreateQueryDef method to create a persistent or temporary query definition.|
|?||Use MakeReplica, Synchronize, and PopulatePartial methods to create and synchronize full or partial replicas of your database.|
|?||Set the CollatingOrder property to establish the alphabetic sorting order for character-based fields in different languages.|
In an ODBCDirect workspace, you can:
|?||Use the Connection property to obtain a reference to the Connection object that corresponds to the Database object.|
Note For a complete list of all methods, properties, and collections available on a Database object in either a Microsoft Jet workspace or ODBCDirect workspace, see the Summary topic.
You use the CreateDatabase method to create a persistent Database object that is automatically appended to the Databases collection, thereby saving it to disk.
You don't need to specify the DBEngine object when you use the OpenDatabase method.
Opening a database with linked tables doesn't automatically establish links to the specified external files or Microsoft Jet-connected ODBC data sources. You must either reference the table's TableDef or Field objects or open a Recordset object. If you can't establish links to these tables, a trappable error occurs. You may also need permission to access the database, or another user might have the database opened exclusively. In these cases, trappable errors occur.
You can also use the OpenDatabase method to open an external database (such as FoxPro, dBASE, and Paradox) directly instead of opening a Microsoft Jet database that has links to its tables.
Note Opening a Database object directly on a Microsoft Jet-connected ODBC data source, such as Microsoft SQL Server, is not recommended because query performance is much slower than when using linked tables. However, performance is not a problem with opening a Database object directly on an external ISAM database file, such as FoxPro, Paradox, and so forth.
When a procedure that declares a Database object has executed, local Database objects are closed along with any open Recordset objects. Any pending updates are lost and any pending transactions are rolled back, but no trappable error occurs. You should explicitly complete any pending transactions or edits and close Recordset objects and Database objects before exiting procedures that declare these object variables locally.
When you use one of the transaction methods (BeginTrans, CommitTrans, or Rollback) on the Workspace object, these transactions apply to all databases opened on the Workspace from which the Database object was opened. If you want to use independent transactions, you must first open an additional Workspace object, and then open another Database object in that Workspace object.
Note You can open the same data source or database more than once, creating duplicate names in the Databases collection. You should assign Database objects to object variables and refer to them by variable name.