3

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
Paul
  • 25,812
  • 38
  • 124
  • 247
  • Have you tried http://docwiki.embarcadero.com/Libraries/Tokyo/en/FireDAC.Comp.Client.TFDCustomConnection.OnRecover ? – RBA Oct 19 '17 at 09:56
  • 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](http://docwiki.embarcadero.com/RADStudio/en/Recovering_Connection_(FireDAC))). Where do you actually execute code you've posted? – Victoria Oct 19 '17 at 10:46
  • @RBA: `OnLost`, `OnRecover` and `OnRestored` are never fired when PostgreSQL stops. – Paul Oct 19 '17 at 11:26
  • @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 Oct 19 '17 at 11:28
  • I would not rely on Firedac states at all. Have a thread execute a small query (something like SELECT 1;) and catch eventual exceptions ... – whosrdaddy Oct 23 '17 at 12:12
  • @Paul Were you able to find a solution? I'm facing the same problem on Delphi 10.1, 10.2 and 10.3 as well. – Andre Batista Mar 11 '19 at 14:03
  • @Andre Batista: No. Working with PostgreSQL was optional in my project and I left it so, without connection loss detection. – Paul Mar 11 '19 at 15:37
  • 1
    @Paul Here a solution according embarcadero quality central. For Delphi 10.3 only: https://stackoverflow.com/questions/55103440/tfdconnection-onrecover-is-never-fired-when-postgresql-stops – Zeus-Adenilton Mar 12 '19 at 18:13

0 Answers0