我使用了 Firedac 连接恢复功能,如下所述恢复连接 (FireDAC) http://docwiki.embarcadero.com/RADStudio/Rio/en/Recovering_Connection_(FireDAC)Delphi XE5 一切正常。
我安装了 Delphi 社区版本 10.2、10.3 和 10.3.1 进行迁移测试,发现数据库重新连接功能无法正常工作。
使用场景:
- Windows 10 专业版 X64 1803
- 德尔福10.2 / 10.3 / 10.3.1
- PostgreSQL 9.5.16 x64
重现问题的步骤:
1 - 创建一个新的VCL应用程序;
2 - 在 Form1 上,放置组件 TFDConnection、TFDPhysPgDriverLink、TFDGUIxWaitCursor、TFDQuery 和 TButton;
3 - 使用 PostgreSQL 的连接参数和 TFDPhysPgDriverLink 的供应商库 libpq.dll 配置 TFDConnection;
4 - 按照以下所述配置 TFDConnection恢复连接 (FireDAC) http://docwiki.embarcadero.com/RADStudio/Rio/en/Recovering_Connection_(FireDAC);
5 - 在 TButton OnClick 事件中放置以下内容:
qry1.Close;
qry1.Open ('select 1');
6 - 在 TFDConnection 的 OnRecover 事件中放置以下代码,如所述恢复连接 (FireDAC) http://docwiki.embarcadero.com/RADStudio/Rio/en/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 - 运行应用程序;
8 - 单击按钮一次;
9 - 重新启动 PostgreSQL 服务或禁用/重新启用网络适配器;
10 - 再次单击 TButton,请注意 TFDConnection 组件没有触发 OnRecover 事件,而是显示以下错误:
[FireDAC] [Phys] [PG] [libpq] 服务器关闭了连接
意外 这可能意味着服务器异常终止
在处理请求之前或期间。
再次单击 TButton 每次都会显示另一个错误:
[FireDAC] [Phys] [PG] [libpq] 没有连接到服务器
预先感谢您对此进行审阅。
这个问题与我的情况相似,但它是针对 Delphi 10 的:当 PostgreSQL 停止时 TFDConnection.Connected 保持 True https://stackoverflow.com/questions/46827156/when-postgresql-stops-tfdconnection-connected-remains-true