The Open method is used to open a connection to a database. Once the connection is open, you can then execute stored procedures or sql statements, or use sql statements to retrieve data from the database you connected to.
Syntax
1 | Connection.Open(ConnectionString, UserID, Password, Options) |
| Name | Type / Value | Description |
|---|---|---|
| ConnectionString | String | The connection information used to establish a connection to the database/engine. |
| ex “Driver=[Microsoft Access Driver (*.mdb)]; DBQ=database_file” | ||
| UserID | String | User name to use when connecting |
| Password | String | The user password to use when connecting. |
| Options | Integer (default = -1) | Extra connection options. This can be one of the ConnectOptionEnum constants: ADO.Enum.ConnectOptionEnum - Enumerated Values |
TroubleShooting
You execute the method and you receive an error.
Try this… Setup a test environment. Here’s what mine looks like
1 | set aCN = CreateObject("ADODB.Connection") |
Line 7 - Application(“ConnectionString”) is a varible containing a connection string.
Sample Connection Strings
1 | aCN.Open "Provider=Microsoft.Jet.OLEDB.3.51; " _ |
Errors
Error while trying to open a connection to the database
-2147467259 - [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Notice my connection string comes from an application variable named ConnectionString. Either your global.asa is missing this declaration, or your the directory holding the global.asa is not setup as an application (this is an IIS setting)
3706 - Provider cannot be found. It may not be properly installed.
file name=\Mdiisia01\urls\TestOracle.udl; user id=a; password=a; Data Source=PD
I get this error when I connect to oracle on a server that does not have the oracle drivers installed.
-2147467259 - Oracle client and networking components were not found. These components are supplied by Oracle Corporation and are part of the Oracle Version 7.3.3 or later client software installation. Provider is unable to function until these components are installed.
file name=\Mdiisia01\urls\TestOracle.udl; user id=a; password=a; Data Source=PD
I get this error when I connect to oracle on a server that does not have oracle installed.
-2147287035 - Access Denied.
file name=\Mdiisia01\urls\TestOracle.udl; user id=a; password=a; Data Source=PD
I get this error when I’m running this from a different server then mdiisia01. Apparently I cannot open files on different servers.
432 - File name or class name not found during Automation operation
file name=C:\Inetpub\wwwroot\EE\TestOracle.udl; user id=wa; password=a; Data Source=PD
I get this error when TestOracle.UDL is missing.