FireDAC.Comp.Client.TFDCustomConnection.Ping

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function Ping: Boolean;

C++

bool __fastcall Ping(void);

Properties

Type Visibility Source Unit Parent
function public
FireDAC.Comp.Client.pas
FireDAC.Comp.Client.hpp
FireDAC.Comp.Client TFDCustomConnection

Description

Pings the DBMS server.

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

When a connection is inactive, the Ping method tries to open a connection.

This function can be used by the clients that remain idle for a long while or work in unstable environments (for example, bad network connection) to check whether the server has closed the connection or is inaccessible, and reconnect if necessary, or the server is accessible to open a connection.

Ping returns True if the connection to the DBMS is working.

Example

procedure TMyDataModule.DoPing(ASender: TObject);
begin
  if not FDConnection1.Ping then
    ShowMessage('Connection is lost!');
end;
.......
FTimer := TTimer.Create;
FTimer.OnTimer := DoPing;
FTimer.Interval := 30000; // each 30 secs
FTimer.Enabled := True;

See Also