When PostgreSQL stops TFDConnection.Connected remains True

半腔热情 提交于 2019-12-07 19:40:08

问题


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

来源:https://stackoverflow.com/questions/46827156/when-postgresql-stops-tfdconnection-connected-remains-true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!