AnyDAC
ContentsIndexHome
PreviousUpNext
TADCustomConnection.Ping Method

Pings the DBMS server.

Group
Links

True, if the connection to the DBMS is working.

The Ping method checks whether a connection to a DBMS server is alive. When the connection is dead and ResourceOptions.AutoReconnect is True, then an automatic reconnection is attempted. When a connection is inactive, the Ping method will try to open a connection. 

This function can be used by the clients that remain idle for a long while or work in non stable environment (eg bad network), to check whether the server has closed the connection or is unaccessible and reconnect if necessary. Or the server is accessible to open a connection.

function Ping: Boolean;
procedure TMyDataModule.DoPing(ASender: TObject);
begin
  if not ADConnection1.Ping then
    ShowMessage('Connection is losted !');
end;
.......
FTimer := TTimer.Create;
FTimer.OnTimer := DoPing;
FTimer.Interval := 30000; // each 30 secs
FTimer.Enabled := True;
What do you think about this topic? Send feedback!