This section describes a simple Visual Basic routine that connects to a database.
You can try this routine by placing a command button named Command1 on a form, and pasting the routine into its Click event. Run the program and click Command1 to connect and then disconnect.
Private Sub cmdTestConnection_Click() ' Declare variables Dim myConn As New ADODB.Connection On Error GoTo HandleError ' Establish the connection myConn.Provider = "ASEOLEDB" myConn.ConnectionString = "Data Source=MANGO:5000;User ID=sa;Pwd=;" myConn.Open MsgBox "Connection succeeded" myConn.Close Exit Sub HandleError: MsgBox "Connection failed" Exit Sub End Sub
The sample carries out the following tasks:
It declares the variables used in the routine.
It establishes a connection, using the Adaptive Server OLE DB Provider, to the sample database.
It closes the connection.
When the ASEOLEDB provider is installed, it registers itself. This registration process includes making registry entries in the COM section of the registry, so that ADO can locate the DLL when the ASEOLEDB provider is called. If you change the location of your DLL, you must re-register it using the following steps:
Registering the Adaptive Server OLE DB Provider
Open a command prompt.
Change to the directory where the Adaptive Server OLE DB Provider is installed.
Register the provider:
regsvr32 sybdrvoledb.dll