Jump to content
mainxt

Main form does not respond when reconnecting TFD Connection

Recommended Posts

Posted (edited)

Hello everyone.
I want to achieve connection restoration when the connection to the SQL server is lost. I use FireDAC and PostgreSQL, Delphi 11.3 CE. And there is a good working example for this: Recovering_Connection_(FireDAC), which completely satisfied me, if not for one problem. This example works well with a regular TFDConnection, but if there is an active TFDEventAlerter in conjunction with it, then the behavior becomes completely different... when choosing AAction := faOfflineAbort or faFail, the form freezes and stops responding. If all this is configured with TFDManager and AutoConnect:=True, then after 3 connection attempts, all connections are interrupted and we have to close the program - then we get an error - FDPhysManager shutdown timeout. Possible reason: application has not released all connection interfaces. If you disable TFDEventAlerter, all problems stop. Does anyone know any standard methods for dealing with this problem? It's strange that components and methods don't work with each other as they should.

Edited by mainxt

Share this post


Link to post
Posted (edited)

A TFDEventAlerter creates it's own new connection when you set the Connection property. So yes, you need to keep track of the TFDEventAlerter objects you create and disable them if the connection is lost. I found it necessary to set Active to false and clear the Connection property.

 

Quote

Set Connection to the component that establishes a connection to the DBMS. Because event alerter is using the connection in a background thread, it will use this connection as a template to create a new internal instance of connection to the DBMS.

 

https://docwiki.embarcadero.com/Libraries/Athens/en/FireDAC.Comp.Client.TFDCustomEventAlerter.Connection

Edited by weirdo12
  • Like 1

Share this post


Link to post
2 hours ago, weirdo12 said:

A TFDEventAlerter creates it's own new connection when you set the Connection property. So yes, you need to keep track of the TFDEventAlerter objects you create and disable them if the connection is lost. I found it necessary to set Active to false and clear the Connection property.

 

 

https://docwiki.embarcadero.com/Libraries/Athens/en/FireDAC.Comp.Client.TFDCustomEventAlerter.Connection

Yes thank you. It really helped. I wrapped it in TTask.Run and it worked more responsively:

 if Assigned(FDEventAlerter.Connection) then
  TTask.Run(
    procedure
    begin
      FDEventAlerter.Connection := nil;
    end);

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×