3
votes

I am connecting to PostgreSQL 9.5 x64 using Delphi 10 and FireDAC.

There is a reconnect feature in my software which relies on TFDConnection.Connected flag:

if not _conn.Connected then
  if _autoConnect then
    _conn.Connected := True
  else
    raise Exception.Create('Not connected to database');

After I connect my software to PostgreSQL and start executing queries, I go to Windows services control panel and stop-start PostgreSQL server in order to test the reconnect feature. After starting PostgreSQL server I continue to get following errors:

[FireDAC][Phys][PG][libpq] no connection to the server

and TFDConnection.Connected remains True no matter whether PostgreSQL is started or stopped.

OnLost, OnRecover and OnRestored are never fired when PostgreSQL stops.

With MS SQL Server 2012, no matter whether local or remote, everything is Ok.

How to detect PostgreSQL disconnection for sure?

Versions of my DLLs are:

libpq.dll      9.5.2.1688
LIBEAY32.dll   1.0.2.7
SSLEAY32.dll   1.0.2.7
libiconv-2.dll 1.14.0.0
libintl-8.dll  0.9.14.0
You are most likely in recovering state. Besides, connection recovering is implemented in FireDAC, so you are working on something that already exists (see Recovering Connection). Where do you actually execute code you've posted? - Victoria
@RBA: OnLost, OnRecover and OnRestored are never fired when PostgreSQL stops. - Paul
@Victoria: In order to be unterstood correctly I repeat: With MSSQL Server everything works as it should. I execute my code in my DBSaver component on timer. It saves data from buffer each second. - Paul
@Paul Here a solution according embarcadero quality central. For Delphi 10.3 only: stackoverflow.com/questions/55103440/… - Zeus-Adenilton