RAD Studio
|
In order to describe a database connection in sufficient detail for TSQLConnection to open a connection, you must identify both the driver to use and a set of connection parameters the are passed to that driver.
The driver is identified by the DriverName property, which is the name of an installed dbExpress driver, such as ASA, ASE, INTERBASE, INFORMIX, ORACLE, MYSQL, MSSQL, DB2 or BlackfishSQL. BlackfishSQL uses the DbxClient driver, which is written entirely in Object Pascal. The rest of these databases use Dynalink drivers, which are partially written in Object Pascal. For Dynalink drivers, the driver name is associated with these files:
The Params property is a string list that lists name/value pairs. Each pair has the form Name=Value, where Name is the name of the parameter, and Value is the value you want to assign.
The particular parameters you need depend on the database server you are using. However, one particular parameter, Database, is required for all servers. Its value depends on the server you are using. For example, with InterBase, Database is the name of the .gdb file, with ORACLE it is the entry in TNSNames.ora, while with DB2, it is the client-side node name.
Other typical parameters include the User_Name (the name to use when logging in), Password (the password for User_Name), HostName (the machine name or IP address of where the server is located), and TransIsolation (the degree to which transactions you introduce are aware of changes made by other transactions). When you specify a driver name, the Params property is preloaded with all the parameters you need for that driver type, initialized to default values.
Because Params is a string list, at design time you can double-click on the Params property in the Object Inspector to edit the parameters using the String List editor. At runtime, use the Params.Values property to assign values to individual parameters.
Although you can always specify a connection using only the DatabaseName and Params properties, it can be more convenient to name a specific combination and then just identify the connection by name. You can name dbExpress database and parameter combinations, which are then saved in a file called dbxconnections.ini. The name of each combination is called a connection name.
Once you have defined the connection name, you can identify a database connection by simply setting the ConnectionName property to a valid connection name. Setting ConnectionName automatically sets the DriverName and Params properties. Once ConnectionName is set, you can edit the Params property to create temporary differences from the saved set of parameter values, but changing the DriverName property clears both Params and ConnectionName.
One advantage of using connection names arises when you develop your application using one database (for example Local InterBase), but deploy it for use with another (such as ORACLE). In that case, DriverName and Params will likely differ on the system where you deploy your application from the values you use during development. You can switch between the two connection descriptions easily by using two versions of the dbxconnections.ini file. At design-time, your application loads the DriverName and Params from the design-time version of dbxconnections.ini. Then, when you deploy your application, it loads these values from a separate version of dbxconnections.ini that uses the "real" database. However, for this to work, you must instruct your connection component to reload the DriverName and Params properties at runtime. There are two ways to do this:
The relationships between connection names and their associated driver and connection parameters is stored in the dbxconnections.ini file. You can create or modify these associations using the Connection Editor.
To display the Connection Editor, double-click on the TSQLConnection component. The Connection Editor appears, with a drop-down list containing all available drivers, a list of connection names for the currently selected driver, and a table listing the connection parameters for the currently selected connection name.
You can use this dialog to indicate the connection to use by selecting a driver and connection name. Once you have chosen the configuration you want, click the Test Connection button to check that you have chosen a valid configuration.
In addition, you can use this dialog to edit the named connections in dbxconnections.ini:
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|