RAD Studio
ContentsIndex
PreviousUpNext
Connecting to the Database Server

The first step when working with a dbExpress 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

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;

 

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).

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!