[Lazarus] Is there a way to reconnect to postgresql if the connection fails?

Luca Olivetti luca at wetron.es
Tue May 15 20:34:59 CEST 2018


I'm trying to devise a strategy for when the connection to the server fails.
I'm using zeos but I also tried with sqldb and I couldn't find a way.
I open a connection to the server, then I stop the server and subsequent 
operations (e.g. refreshing a query) fail (obviously since the 
connection has been severed).
However, for the same reason, I cannot close the connection (with sqldb 
by setting PQConnection.connected:=false or with zeos by calling 
ZConnection.Disconnect), since it raises an exception :-(
With zeos I tried to get hold of the underlying handle and call PQReset 
before closing the connection.
The PQreset works, but the connection cannot be closed because it tries 
to release prepared statements that don't exist in the new connection so 
postgresql returns an error.....

Is there a way to force the closing of a connection in this case so I 
can try and reopen it again?

Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007

More information about the Lazarus mailing list