Configuring TSQL Connection
Go Up to Using dbExpress
The first step when working with a unidirectional dataset is to connect it to a database server. At design time, once a dataset has an active connection to a database server, the Object Inspector can provide drop-down lists of values for other properties. For example, when representing a stored procedure, you must have an active connection before the Object Inspector can list what stored procedures are available on the server. The connection to a database server is represented by a separate TSQLConnection component. You work with TSQLConnection like with any other database connection component.
Metaprocedure: Configuring a TSQL Connection
- Choose File > New > Windows VCL Application - Delphi .
- From the dbExpress category of the Tool Palette, drag a TSQLConnection component to the form.
- Identify the driver (see the steps below).
- Specify connection parameters (see the steps below).
- Identify a database connection (see the steps below).
- Display and use the dbExpress Connection Editor (see the steps below).
To identify the driver
- Select the TSQLConnection component.
- In the Object Inspector, set the DriverName property to an installed dbExpress driver from the combo box that holds all the driver names.
- Identify the files associated with the driver name. Select any of the following:
- The dbExpress driver
- The dynamic link library
Note: The relationship between the dbExpress driver or dynamic link library and the database name is stored in a file called dbxdrivers.ini, which is updated when you install a dbExpress driver. The SQL connection component looks up the dbExpress driver and the dynamic-link library in dbxdrivers.ini when given the value of DriverName. When you set the DriverName property, TSQLConnection automatically sets the LibraryName and VendorLib properties to the names of the associated dlls. Once LibraryName and VendorLib have been set, your application does not need to rely on dbxdrivers.ini.
To specify a connection parameter
- Double-click the Params property in the Object Inspector to edit the parameters using Value List Editor at design time.
- Use the Params.Values property to assign values to individual parameters at run time.
To identify a database connection
- Set the ConnectionName property to a valid connection name. This automatically sets the DriverName and Params properties.
- Edit the Params property to change the saved set of parameter values.
- Set the LoadParamsOnConnect property to True to develop your application using one database and deploy it using another. This causes TSQLConnection to automatically set DriverName and Params to the values associated with ConnectionName in dbxconnections.ini when the connection is opened.
- Call the LoadParamsFromIniFile method. This method sets DriverName and Params to the values associated with ConnectionName in dbxconnections.ini (or in another file that you specify). You can use this method if you want to override certain parameter values before opening the connection.
To display the Connection Editor
- Double-click the TSQLConnection component. The dbExpress Connection Editor appears, with a drop-down drivers list, a list of connection names for the currently selected driver, and a connection parameters table for the currently selected connection name.
- From the Driver Name drop-down list, select a driver to indicate the connection to use.
- From the Connection Name list, select a connection name.
- Choose the configuration you prefer.
- Click the Test Connection button to check for a valid configuration.
To define and modify connections using the Connection Editor
- To edit the currently selected named connections in dbxconnections.ini, edit the parameter values in the parameter table.
- Click OK. The new parameter values are saved to dbxconnections.ini.
- Click the Add Connection button to define a new connection. The New Connection dialog appears.
- In the New Connection dialog box, set the Driver Name and the Connection Name.
- Click OK.
- Click the Delete Connection button to delete the currently selected named connection from dbxconnections.ini.
- Click the Rename Connection button to change the name of the currently selected named connection.
See Also
- dbExpress Components
- Setting Up TSQLConnection
- Specifying What Data to Display
- Fetching the Data
- Executing the Commands using TSQLDataSet
- Accessing Schema Information
- Debugging dbExpress Applications
- Using TSQLTable
- Using TSQLStoredProc (Procedure)
- Using TSQLQuery
- Using TSimpleDataSet
- Using dbExpress Datasets