AnyDAC
ContentsIndexHome
PreviousUpNext
TADCustomConnection.Connected Property

Gets / sets connection active status.

Group
Links

Set Connected to True to establish a connection to a DBMS. Set Connected to False to close a connection. The default value for Connected is False. 

An application can check Connected to determine the current status of a connection. If Connected is True, the connection is active; if False, and the KeepConnection property is also False, then the connection is inactive. 

To open connection, it must be setup in one of the following ways:

  1. Set ConnectionDefName to a name of one of a existing connection definitions and optionally override connection definition parameters in Params. Existing connection definition may be defined either in connection definitions INI file or created on fly, for example, using TADCustomManager.AddConnectionDef;
  2. Set DriverName to a name of one of a registered drivers (or add DriverID into Params) and specify connection definition parameters in Params.

When the connection definition is pooled (Pooled=True), then use (1) and does not override any of parameters, otherwise you will get an exception. 

Setting Connected to False will try to connect to a DB. If somehow the connecting fails, then Connected will remain False and an an exception will be raised. If connecting failed due to a DB unavailability, then application may use Automatic Connection Recovery feature to wait and try to establish the connection. 

Setting Connected to False will disconnect (close and unprepare) all associated commands and datasets. If you just need to disconnect from DBMS, but does not close objects, then use Offlined property.

property Connected;

TCustomConnection.BeforeConnect, TCustomConnection.AfterConnect, TCustomConnection.BeforeDisconnect, TCustomConnection.AfterDisconnect, ConnectionDefName, DriverName, Params, Offlined, OnRecover

ADConnection1.ConnectionDefName := 'ASA_Demo';
ADConnection1.Connected := True;

See AnyDAC\Samples\Comp Layer\TADConnection\Pooling sample for details of how to work with pooled connections.

What do you think about this topic? Send feedback!