Using Microsoft ActiveX Data Objects (ADO) from Microsoft Visual Basic or Visual Basic for Applications (VBA), how do I connect to my InterBase database without setting up an ODBC data source?

This article describes how to use a DSN-less connection that connects to an InterBase database from Visual Basic or VBA by using the Easysoft InterBase ODBC driver.

  1. Create a Connection object:
    Dim con As New ADODB.Connection
    
  2. Use the Open method to connect to the database. For example:
    con.Open "Driver={Easysoft Interbase ODBC};" _
        & "Database=myinterbaseserver:c:\myinterbasedatabase.gdb;" _
        & "UID=myinterbaseusername;PWD=myinterbaseusername"
    

    For more information about the InterBase ODBC driver attributes that you can specify in the Open method's ConnectionString argument, refer to the InterBase ODBC driver documentation.

  3. You can then query the connection by using a Recordset object. The following code fetches some data and displays the results in the Immediate window:
    Dim rs As New ADODB.Recordset
    
    rs.Open "select column from mytable", con
    
    Do Until rs.EOF
       Debug.Print rs.Fields(0)
       rs.MoveNext
    Loop
    
  4. Close any used recordsets and connections:
    rs.Close
    con.Close
    

    Note When you close a connection in ADO, the connection only closes in your program. ADO keeps the connection alive in case you connect again.