gpt4 book ai didi

delphi - 当 PostgreSQL 停止时,TFDConnection.OnRecover 永远不会被触发

转载 作者:行者123 更新时间:2023-12-03 15:34:35 27 4
gpt4 key购买 nike

我使用了 Firedac 连接恢复功能,如 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 - 按照 Recovering Connection (FireDAC) 中所述配置 TFDConnection ;

5 - 在 TButton OnClick 事件中放置以下内容:

qry1.Close;
qry1.Open ('select 1');

6 - 在 TFDConnection 的 OnRecover 事件中放置以下代码,如 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 - 单击 TButton 一次;

9 - 重新启动 PostgreSQL 服务或禁用/重新启用网络适配器;

10 - 再次单击 TButton,注意 TFDConnection 组件没有触发 OnRecover 事件,而是显示以下错误:

[FireDAC] [Phys] [PG] [libpq] server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.

再次单击 TButton 每次都会显示另一个错误:

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

提前感谢您审阅本文。

这个问题与我的情况相似,但它是针对 Delphi 10 的: When PostgreSQL stops TFDConnection.Connected remains True

最佳答案

我根据 RSP-23958 向 Embarcadero 质量中心报告了这个问题,并且该错误已得到解决。一位名叫 Dmitry 的人回答说,该问题将在 Delphi 10.3 的更新 2 中得到解决。

在 RSP-23958 中,附加了一个解决该问题的修复补丁,如果您有带有 Firedac 源代码的 Dephi,并且 Delphi 10.3 update 2 尚未发布,则可以使用它。

解决方法如下:

Index: runtime/data/firedac/FireDAC.Phys.PGWrapper.pas
===================================================================
--- runtime/data/firedac/FireDAC.Phys.PGWrapper.pas (revision 95224)
+++ runtime/data/firedac/FireDAC.Phys.PGWrapper.pas (revision 95225)
@@ -1109,7 +1109,9 @@
FDStrLike(sLCMessage, 'password authentication failed for user "%"') then
eKind := ekUserPwdInvalid
else if (Pos('connection refused', sLCMessage) <> 0) or
- (Pos('could not connect to server', sLCMessage) <> 0) then
+ (Pos('could not connect to server', sLCMessage) <> 0) or
+ (Pos('server closed the connection unexpectedly', sLCMessage) <> 0) or
+ (Pos('no connection to the server', sLCMessage) <> 0) then
eKind := ekServerGone
else
eKind := ekOther;

关于delphi - 当 PostgreSQL 停止时,TFDConnection.OnRecover 永远不会被触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55103440/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com