Configuring and Using ODBC Data Sources
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:
Start | Settings | Control Paneland 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.
- On the
User DSNtab, click Add. The “Create New Data Source” window opens.
- Select the InterBase ODBC driver and click Finish. The “InterBase ODBC Configuration” window opens.
- Enter the following information:
Data Source Name Make up a name for your data source
A description of the data course (not required)
Choose the protocol from the drop-down list
Full physical path to the database, including the database name
Server name; if you choose the protocol “local,” this will default to the local server
Your database user name, or SYSDBA
The database password corresponding to the Username
- Optionally, click Advanced and fill in CharacterSet and Roles information.
- 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.
- Drop a TQuery, a TDatasource, and a TDBGrid component on a Delphi form.
- Set the following properties for the TQuery component:
Pick from the list the data source name created using ODBC Administrator
enter the SQL statement to be executed; for example, “SELECT * FROM Table1”
Set to True to connect; supply user name and password on connection
- Set the following property for the TDatasource component:
Set to the name of the TQuery component, or “query1” in this case
- Set the following property for the TDBGrid component:
Set to the name of the TDatasource component, or “datasource1” in this case
- Inspect the returned results from the SELECT statement, in the DBGrid area.