Download Delphi 7 Developers Guide

Transcript
Connecting to the database server
The connection to a database server is represented by a separate TSQLConnection
component. You work with TSQLConnection like any other database connection
component. For information about database connection components, see Chapter 23,
“Connecting to databases.”
To use TSQLConnection to connect a unidirectional dataset to a database server, set
the SQLConnection property. At design time, you can choose the SQL connection
component from a drop-down list in the Object Inspector. If you make this
assignment at runtime, be sure that the connection is active:
SQLDataSet1.SQLConnection := SQLConnection1;
SQLConnection1.Connected := True;
Typically, all unidirectional datasets in an application share the same connection
component, unless you are working with data from multiple database servers.
However, you may want to use a separate connection for each dataset if the server
does not support multiple statements per connection. Check whether the database
server requires a separate connection for each dataset by reading the
MaxStmtsPerConn property. By default, TSQLConnection generates connections as
needed when the server limits the number of statements that can be executed over a
connection. If you want to keep stricter track of the connections you are using, set the
AutoClone property to False.
Before you assign the SQLConnection property, you will need to set up the
TSQLConnection component so that it identifies the database server and any required
connection parameters (including which database to use on the server, the host name
of the machine running the server, the username, password, and so on).
Setting up TSQLConnection
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.
Identifying the driver
The driver is identified by the DriverName property, which is the name of an installed
dbExpress driver, such as INTERBASE, INFORMIX, ORACLE, MYSQL, MSSQL, or
DB2. The driver name is associated with two files:
• The dbExpress driver. This can be either a dynamic-link library with a name like
dbexpint.dll, dbexpora.dll, dbexpmysql.dll, dbexpmss.dll, or dbexpdb2.dll, or a
compiled unit that you can statically link into your application (dbexpint.dcu,
dbexpora.dcu, dbexpmys.dcu, dbexpmss.dcu, or dbexpdb2.dcu).
• The dynamic-link library provided by the database vendor for client-side support.
Using unidirectional datasets
28-3