I used the Firedac connection recovery feature as described at Recovering Connection (FireDAC) and everything worked fine with Delphi XE5.
I installed Delphi community versions 10.2, 10.3 and 10.3.1 for migration testing and found that the database reconnect feature is not working as it should.
Scenario of use:
- Windows 10 PRO X64 1803
- Delphi 10.2 / 10.3 / 10.3.1
- PostgreSQL 9.5.16 x64
Steps to reproduce the problem:
1 - Create a new VCL application;
2 - On Form1, drop the components TFDConnection, TFDPhysPgDriverLink, TFDGUIxWaitCursor, TFDQuery and TButton;
3 - Configure the TFDConnection with the connection parameters for PostgreSQL and vendorlib libpq.dll for TFDPhysPgDriverLink;
4 - Configure the TFDConnection as described at Recovering Connection (FireDAC);
5 - In the TButton OnClick event place the following:
qry1.Close;
qry1.Open ('select 1');
6 - In the OnRecover event of TFDConnection put the code below, as described at Recovering Connection (FireDAC):
var
iRes: Integer;
begin
iRes: = MessageDlg ('Connection is lost. Offline - yes, Retry - ok, Fail - Cancel', mtConfirmation, [mbYes, mbOK, mbCancel], 0);
case iRes of
mrYes: AAction: = faOfflineAbort;
mrOk: AAction: = faRetry;
mrCancel: AAction: = faFail;
end;
// Log ('Connection is recovering');
7 - Run the application;
8 - Click the TButton once;
9 - Restart the PostgreSQL service or disable / re-enable the network adapter;
10 - Click on the TButton again and note that the TFDConnection component didn't trigger the OnRecover event, instead, the following error is displayed:
[FireDAC] [Phys] [PG] [libpq] server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.
Clicking again on the TButton another error is displayed every time:
[FireDAC] [Phys] [PG] [libpq] no connection to the server
Thanks in advance for reviewing this.
This question has similarity to my case, but it was for Delphi 10: When PostgreSQL stops TFDConnection.Connected remains True