>
RegisterDatabase Method
Applies To
DBEngine Object.
Description
Enters connection information for an ODBC data source in the ODBC.INI file. The ODBC driver needs connection information when the Microsoft Jet database engine opens the data source during a session.
Syntax
DBEngine.RegisterDatabase dbname, driver, silent, attributes
The RegisterDatabase method syntax has these parts.
Part | Description |
|
dbname | A string expression that is the name used in the OpenDatabase method that refers to a block of descriptive information about the data source. For example, if the data source is an ODBC remote database, it could be the name of the server. |
driver | A string expression that is the name of the ODBC driver. This isn't the name of the ODBC driver DLL file. For example, SQL Server is a driver name, but SQLSRVR.dll is the name of a DLL file. You must have ODBC and the appropriate driver already installed. |
Part | Description |
|
silent | A numeric expression that is True if you don't want to display the ODBC driver dialog boxes that prompt for driver-specific information or False if you do want to display the ODBC driver dialog boxes. If silent is True, attributes must contain all the necessary driver-specific information or the dialog boxes are displayed anyway. |
attributes | A string expression that is a list of keywords to be added to the ODBC.INI file. The keywords are in a carriage-return–delimited string. |
Remarks
If the database is already registered (connection information is already entered) in the ODBC.INI file when you use the RegisterDatabase method, the connection information is updated.
In 32-bit installations, most of the ODBC registration information is maintained in the Windows registration database and not in the ODBC.INI file.
If the RegisterDatabase method fails for any reason, no changes are made to the ODBC.INI file, and an error occurs.
For more information about ODBC drivers such as SQL Server, see the Help file provided with the driver.
You are encouraged to use the Windows Control Panel ODBC setup icon to add new data sources, or to make changes to existing entries. However, if you choose to use the RegisterDatabase method, you are encouraged to set the silent option to True.
See Also
Database Object, OpenDatabase Method.
Example
This example registers a SQL Server data source named PtLudlow and then opens the database MySQLDb on that server.
Using the Windows ODBC control panel icon is the preferred way to create, modify, or delete data source names.
Dim dbsLudlow As Database
Dim strAttribs As String
' Build keywords string.
strAttribs = "Description=SQL Server on server PtLudlow" & _
Chr$(13) & "OemToAnsi=No" & Chr$(13) & "Network=DBNMP3" & _
Chr$(13) & "Address=\\PTLUDLOW\PIPE\SQL\QUERY" & Chr$(13) & _
"Database=MySQLDb"
' Update ODBC.INI.
DBEngine.RegisterDatabase "PtLudlow", "SQL Server 32", True, strAttribs
' Open the database.
Set dbsLudlow = DBEngine.Workspaces(0).OpenDatabase("PtLudlow", _
False, False, "ODBC;")