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.
- Create a
Connection
object:Dim con As New ADODB.Connection
- 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'sConnectionString
argument, refer to the InterBase ODBC driver documentation. - 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
- 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.