Configuring TSQL Connection
Go Up to How To Perform Database Procedures
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 any other database connection component.
Metaprocedure: Configuring a TSQL Connection
- Choose File > New > Other. The New Items dialog appears.
- In the New Items dialog, select Delphi Projects and double-click VCL Forms Application. The Windows Designer displays.
- From the dbExpress category of the Tool Palette, drag a TSQLConnection component to the form.
- Identify the driver (see steps below).
- Specify connection parameters (see steps below).
- Identify a database connection (see steps below).
- Display and use the dbExpress Connection Editor (see steps below).
To identify the driver
- Select the TSQLConnection component.
- In the Object Inspector, set the DriverName property to an installed dbExpress driver.
- 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 the dbExpress driver and the dynamic-link library up 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 might choose to use this method if you want to then 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 that you want.
- 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.