Contents Index ADO programming with Adaptive Server Anywhere Executing statements with the Command object

ASA Programming Guide
  The OLE DB and ADO Programming Interfaces
    ADO programming with Adaptive Server Anywhere

Connecting to a database with the Connection object


This section describes a simple Visual Basic routine that connects to a database.

Sample code 

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 the button to connect and then disconnect.

Private Sub cmdTestConnection_Click()
    ' Declare variables
    Dim myConn As New ADODB.Connection
    Dim myCommand As New ADODB.Command
    Dim cAffected As Long

    On Error GoTo HandleError

    ' Establish the connection
    myConn.Provider = "ASAProv"
    myConn.ConnectionString = _
      "Data Source=ASA 9.0 Sample"
    myConn.Open
    MsgBox "Connection succeeded"
    myConn.Close
    Exit Sub

HandleError:
    MsgBox "Connection failed"
    Exit Sub
End Sub
Notes 

The sample carries out the following tasks:

When the ASAProv 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 ASAProv provider is called. If you change the location of your DLL, you must reregister it.

To register the OLE DB provider

  1. Open a command prompt.

  2. Change to the directory where the OLE DB provider is installed.

  3. Enter the following command to register the provider:

    regsvr32 dboledb9.dll

For more information about connecting to a database using OLE DB, see Connecting to a database using OLE DB.


Contents Index ADO programming with Adaptive Server Anywhere Executing statements with the Command object