Configuring and Using ODBC Data Sources

From InterBase
Jump to: navigation, search

Go Up to Programming Applications with ODBC


Use the ODBC Administrator to configure data sources. To access the ODBC Administrator on Windows platforms, display the Control Panel and choose ODBC (in some cases, it appears as “32-bit ODBC Administrator” or “ODBC Data Source Administrator” or “ODBC Data Sources”).

Note: A user data source is a data source visible to the user, whereas a system data source is visible to the system.


Configuring Data Sources

Below are the steps for configuring a data source:

  1. Select Start | Settings | Control Panel and double-click the ODBC entry. (If you have the ODBC SDK installed, you can run the “32bit ODBC Administrator” utility instead). The “ODBC Data Source Administrator” window opens.
  2. On the User DSN tab, click Add. The “Create New Data Source” window opens.
  3. Select the InterBase ODBC driver and click Finish. The “InterBase ODBC Configuration” window opens.
  4. Enter the following information:
    Data Source Name Make up a name for your data source

    Description

    A description of the data course (not required)

    Network Protocol

    Choose the protocol from the drop-down list

    Database

    Full physical path to the database, including the database name

    Server

    Server name; if you choose the protocol “local,” this will default to the local server

    Username

    Your database user name, or SYSDBA

    Password

    The database password corresponding to the Username

  5. Optionally, click Advanced and fill in CharacterSet and Roles information.
  6. Click OK to return to the “ODBC Data Source Administrator” window. You should see the data source you just added, listed under User Data Sources.


Connecting from Delphi Using the ODBC Data Source

ODBC connection from Delphi is very similar to connecting using BDE from Delphi.

The following example shows connecting using the TQuery component, and also displaying the results of an SQL statement.

  1. Drop a TQuery, a TDatasource, and a TDBGrid component on a Delphi form.
  2. Set the following properties for the TQuery component:

    DatabaseName

    Pick from the list the data source name created using ODBC Administrator

    SQL

    enter the SQL statement to be executed; for example, “SELECT * FROM Table1”

    Active

    Set to True to connect; supply user name and password on connection

  3. Set the following property for the TDatasource component:

    Data Set

    Set to the name of the TQuery component, or “query1” in this case

  4. Set the following property for the TDBGrid component:

    Data Set

    Set to the name of the TDatasource component, or “datasource1” in this case

  5. Inspect the returned results from the SELECT statement, in the DBGrid area.

Advance To: