There are too few Chinese documents for TSQLConnection. Here is the English document of embaradero, which is translated into Chinese and has a limited level. You are welcome to make a picture.
Setting Up TSQLConnection
Set TSQLConnection
Original article address:
Http://docwiki.embarcadero.com/RADStudio/XE2/en/Setting_Up_TSQLConnection
Go Up to Using dbExpress Components Index
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.
To more effectively describe the database connection to TSQLConnection (connected to the database), you must identify the database driver used and a series of parameters of the database driver.
Contents
- 1 Identifying the driver
- 2 Specifying connection parameters
- 3 Naming a connection description
- 4 Using the Connection Editor
- 5 See Also
Content
1. Identify the driver
2. Specify database connection Parameters
3. Name a database connection description
4. Use the database connection Editor
5. Others
Identifying the driver
The driver is identified byDriverName
Property, which is the name of an installedDbExpressDriver, such as ASA, ASE, Datasnap, Db2, Firebird, Informix, InterBase, MSSQL, MSSQL9, MySQL, Odbc, and Oracle. these databases use Dynalink drivers, which are partially written in Object Pascal. for Dynalink drivers, the driver name is associated with these files:
- TheDbExpressDriver. This is a dynamic-link library with a name like dbx *. dll. For example, the Interbase driver DLL begins with "dbxint" and the Oracle driver DLL begins with "dbxora"
- The dynamic-link library provided by the database vendor for client-side support.
Recognize database drivers
The DriverName attribute is used to differentiate database drivers, such as dbExpress, ASA, ASE, Datasnap, DB2, Firebird, Informix, InterBase, MSSQL, MSSQL9, MySql, ODBC, and oracle. These databases are driven by dynamic link libraries, which are part of Object Pascal. For the dynamic link library driver, the driver library name is associated with the following files:
* DbExpress database driver. It is a dynamic link library named like dbx *. dll. For example, the Interbase data program starts with dbxint, and Oracle uses dbxora
* The Dynamic Link Library provides database developers with support for database applications.
The relationship between these files and the database name is stored in a file called dbxdrivers. ini, which is updated when you installDbExpressDriver. Typically, you do not need to worry about these files because the SQL connection component looks them up in dbxdrivers. ini when given the valueDriverName. When you setDriverNameProperty,TSQLConnectionAutomatically setsLibraryNameAndVendorLibProperties to the names of the associated dlls. OnceLibraryNameAndVendorLibHave been set, your application does not need to rely on dbxdrivers. ini. (That is, you do not need to deploy dbxdrivers. ini with your application unless you setDriverNameProperty at run time .)
The relationship between these files and database names is stored in the file dbxdrivers. ini. When you install a dbExpressdriver (database), these files will be updated. You don't have to worry about these files, because when the SQL connection is set to Drivername, they will query the file dbxdrivers. ini. When DriverName is set, TSQLConnection automatically sets LibraryName and VendorLib as the associated dll. Once LibraryName and VendorLib are set, your application will not depend on dbxdrivers. ini. (in other words, at runtime, your application does not need to configure the file dbxdrivers. ini unless you reset the DriverName attribute)
Specifying connection parameters
TheParamsProperty is a string list that lists name-value pairs. Each pair has the formName=Value, WhereNameIs the name of the parameter, andValueIs the value you want to assign.
The particle parameters you need depend on the database server you are using. However, one particle parameter,Database, Is required for all servers. Its value depends on the server you are using. For example, with InterBase,DatabaseIs 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 includeUser_Name(The name to use when logging in ),Password(The passwordUser_Name),HostName(The machine name or IP address of where the server is located), andTransIsolation(The degree to which transactions you introduce are aware of changes made by other transactions). When you specify a driver name,ParamsProperty is preloaded with all the parameters you need for that driver type, initialized to default values. You can also add other connection parameters toParamsString list, according to your application's needs. for example, to provide Multiple Active Result Set (MARS) support to a SQL connection using the MSSQL driver, you must add a key called Mars_Connection and set its value to True.
BecauseParamsIs a string list, at design time, you can double-clickParamsProperty inObject InspectorTo edit the parameters using the String List editor. At run time, useParams. ValuesProperty to assign values to individual parameters.
Specify connection Parameters
The property Params is a pair of name-value strings. Each pair of parameters you assign a value has a name and a value.
The database service you use has its own special parameters. However, a special parameter, Database, is required for all services. Its value depends on the database service you are using. For example, the Database Interbase is used, and the Database name is file. gdb: uses the ORACLE Database. The full name of the Database is TNSNames. ora. When using DB2, It is the name of the client node (???).
Other typical parameters include UserName, Password, and HostName (server name or server address). When transmitting (), you need to specify the driver name of the database, the Params parameter is preloaded based on the database driver type you need and initialized to the default value. You can add some other connection parameters in the Params list according to the application. For example, a parallel active result set (MARS) is provided to support SQL connections. To use the MSSQL database driver, you must add the parameter Mars_Connection and set it to True.
In the design phase, Params is a character production list. You can double-click it in the object viewer and use the string editor to set its attribute values. You can assign values to the Params attribute values at runtime.
Naming a connection description
Although you can always specify a connection using onlyDatabaseNameAndParamsProperties, it can be more convenient to name a specific combination and then just identify the connection by name. You can nameDbExpressDatabase 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 settingConnectionNameProperty to a valid connection name. SettingConnectionNameAutomatically setsDriverNameAndParamsProperties. OnceConnectionNameIs set, you can editParamsProperty to create temporary differences from the saved set of parameter values, but changingDriverNameProperty clears bothParamsAndConnectionName.
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,DriverNameAndParamsWill 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 loadsDriverNameAndParamsFrom 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 reloadDriverNameAndParamsProperties at run time. There are two ways to do this:
- SetLoadParamsOnConnectPropertyTrue. This causesTSQLConnectionTo automatically setDriverNameAndParamsTo the values associatedConnectionNameIn dbxconnections. ini when the connection is opened.
- CallLoadParamsFromIniFileMethod. This method setsDriverNameAndParamsTo the values associatedConnectionNameIn 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.
Name a connection description
Although you can specify a database connection through the attribute DatabaseName and Params, it is more effective to bind and identify the connection name. You can name the dbExpress database and bind parameters. They are stored in the dbxconnections. ini file. Each connection name is a combination name.
Once you have defined a connection name, you can use a simple and effective connection name to identify a database connection. With ConnectionName, attributes DriverName and Params can be set automatically. Once the connection name is set, you can edit the attribute Params to create a temporary connection different from the saved parameter set. However, once the DriverName is changed, the Params and ConnecitonName will be cleared.
One advantage of using Conneciton names is that when you develop a database application (such as a local Interbase Database), it is released by another database (such as Oracle ). In that case, DriverName and Params may be different from the value you developed. You can easily convert two databases through the file dbxconnections. ini. During the design period, your application loads DriverName and Params from dbxconnections. ini. Then, when you publish an application, the program can load the actual database from dbxconnections. ini. However, in order for the program to run normally, you must notify your connection component to re-load DriverName and Params at runtime. There are two methods:
* Set LoadParamsOnConnect to True. This is because when the database is connected, TSQLConnection automatically sets the DriverName and Params values through the ConnectionName in the file dbxconnections. ini.
* Call the LoadParamsFromIniFile method. This method sets the DriverName and Params values in dbxconnections. ini (or through the ConnectionName in the file you specify. Before you start a database connection, you can overwrite (specify) a specific parameter value.
Using the Connection Editor
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-clickTSQLConnectionComponent. 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:
- Edit the parameter values in the parameter table to change the currently selected named connection. When you exit the dialog by clicking OK, the new parameter values are saved to dbxconnections. ini.
- Click the Add Connection button to define a new named connection. A dialog appears where you specify the driver to use and the name of the new connection. once the connection is named, edit the parameters to specify the connection you want and click the OK button to save the new connection to dbxconnections. ini.
- 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. Note that any edits you have made to the parameters are saved with the new name when you click the OK button.
Use the database connection Editor
In the relationship between the Driver and Connection parameters stored in the file dbxconnections. ini associated with connection Names, you can create or change their associations through Connection Editor.
Double-click the TSQLConnection component to implement the Connection Editor. The Connection Editor contains the drop-down list of the currently available drivers and the Connection parameter of the currently available Connection name.
You can use this dialog box to set a Connection by selecting the Driver and connection name. Once you select the configuration you need, click the test button to check whether your configuration is correct.
In addition, you can use this dialog box to edit named connections in the file dbxconnections. ini.
* Change the named connection you selected, and edit the parameter values in the parameter list. When you click OK to exit the dialog box, the new parameter value is saved in the dbxconnections. ini file.
* Click the delete link to delete the selected named connection from the file dbxconnections. ini.
* Click the rename button to rename the selected named connection. Remember, when you click OK, any edits you make to Parameters are saved as a new name.