PostgreSQL停止时永远不会触发TFDConnection.OnRecover [英] TFDConnection.OnRecover is never fired when PostgreSQL stops
问题描述
我使用了Firedac连接恢复功能,如恢复连接(FireDAC)中所述,并且一切都可以在Delphi XE5上正常工作。
I used the Firedac connection recovery feature as described at Recovering Connection (FireDAC) and everything worked fine with Delphi XE5.
我安装了Delphi社区版本10.2、10.3和10.3.1进行迁移测试,发现数据库重新连接功能
I installed Delphi community versions 10.2, 10.3 and 10.3.1 for migration testing and found that the database reconnect feature is not working as it should.
使用场景:
- Windows 10 PRO X64 1803
- Delphi 10.2 / 10.3 / 10.3.1
- PostgreSQL 9.5.16 x64
重现该问题的步骤:
1-创建一个新的VCL应用程序;
1 - Create a new VCL application;
2-在Form1上,删除组件TFDConnection,TFDPhysPgDriverLink,TFDGUIxWaitCursor,TFDQuery和TButton;
2 - On Form1, drop the components TFDConnection, TFDPhysPgDriverLink, TFDGUIxWaitCursor, TFDQuery and TButton;
3-使用PostgreSQL和vendorlib libpq.dll的连接参数配置TFDConnection for TFDPhysPgDriverLink;
3 - Configure the TFDConnection with the connection parameters for PostgreSQL and vendorlib libpq.dll for TFDPhysPgDriverLink;
4-按照恢复连接(FireDAC);
5-在TButton OnClick事件中放置以下内容:
5 - In the TButton OnClick event place the following:
qry1.Close;
qry1.Open ('select 1');
6-在TFDConnection的OnRecover事件中,将代码放在下面,如恢复连接(FireDAC):
6 - In the OnRecover event of TFDConnection put the code below, as described at 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-运行应用程序;
7 - Run the application;
8-单击一次TButton;
8 - Click the TButton once;
9-重新启动PostgreSQL服务或禁用/重新启用网络适配器;
9 - Restart the PostgreSQL service or disable / re-enable the network adapter;
10-再次单击TButton,请注意TFDConnection组件没有触发OnRecover事件,而是显示以下错误:
10 - Click on the TButton again and note that the TFDConnection component didn't trigger the OnRecover event, instead, the following error is displayed:
[FireDAC] [Phys] [PG] [libpq]服务器意外关闭了连接
,这可能意味着服务器在处理请求之前或期间异常终止了
。
[FireDAC] [Phys] [PG] [libpq] server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.
再次单击TButton每次都会显示另一个错误:
Clicking again on the TButton another error is displayed every time:
[FireDAC] [Phys] [PG] [libpq]没有与服务器的连接
[FireDAC] [Phys] [PG] [libpq] no connection to the server
在此先感谢您对此进行审查。
Thanks in advance for reviewing this.
此问题与我的情况相似,但适用于Delphi 10:
当PostgreSQL停止TFDConnection.Connected仍为True
This question has similarity to my case, but it was for Delphi 10: When PostgreSQL stops TFDConnection.Connected remains True
推荐答案
我根据RSP-23958向Embarcadero质量中心报告了此问题,并且对该错误进行了认可。有人叫德米特里(Dmitry)回答说,该问题将在Delphi 10.3的更新2中得到解决。
I reported this problem to Embarcadero quality central, according RSP-23958, and the bug are comproved of them. Someone called Dmitry answered that the problem will be fixed with update 2 of Delphi 10.3.
在RSP-23958中,附有一个解决该问题的修复程序,您如果您具有带有Firedac源代码的Dephi,而Delphi 10.3 Update 2没有发布,则可以使用它。
In the RSP-23958, was attached a fix patch that solve the problem and you you can use it, if you have Dephi with Firedac source code, while Delphi 10.3 update 2 not released.
解决方法如下:
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;
这篇关于PostgreSQL停止时永远不会触发TFDConnection.OnRecover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!