PostgreSQL disconnect identification

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
execoma
Posts: 9
Joined: Thu 27 Jan 2011 14:10

PostgreSQL disconnect identification

Post by execoma » Mon 10 Feb 2014 17:35

Hello! When I do a forced disconnection (close PostgreSQL), TUniConnection does not execution none events (no BeforeDisconnect and no AfterDisconnect). Exception generated only when one of the data components try execute the query. I want catch exception immediately when TCP/IP connection is closed. Why events not executed immediately? It's a persistent TCP connection? How I can catch disconnection? Please, help me.

p.s. Options.DisconnectedMode is OFF.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: PostgreSQL disconnect identification

Post by AlexP » Tue 11 Feb 2014 08:03

Hello,

If no actions (SELECT, INSERT, UPDATE, etc.) occur in the application, data is not sent to the server. If you stop the server, disable the network, etc., then the server won't send any information about disconnection, therefore events don't function. To determine the state of server/connection, you can run serially simple commands, such as SELECT 1, and handle server connection loss in the onConnectionLost event

execoma
Posts: 9
Joined: Thu 27 Jan 2011 14:10

Re: PostgreSQL disconnect identification

Post by execoma » Tue 11 Feb 2014 09:45

I have a timer which updates the Tables, therefore I have the right exception. But between Timer iterations it is possible that user actions throwing an exception in other methods. It's not critical, but not an ideal realization. I still do not understand why without queries can not get Disconnect. In the component uses a persistent connection via TCP sockets? Well then there is Disconnect should operate independently of any queries. This mechanism is provided by the sockets. This possibility in this component is not used. If it was not a persistent connection, there would be no questions.

execoma
Posts: 9
Joined: Thu 27 Jan 2011 14:10

Re: PostgreSQL disconnect identification

Post by execoma » Wed 12 Feb 2014 10:42

I think I understand why it is done. Otherwise would be required to use an additional Thread in the component. So all good

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: PostgreSQL disconnect identification

Post by AlexP » Wed 12 Feb 2014 12:46

When opening a connection, the socket is open all the time, but if no actions are performed either on server side or on client side - data is not transferred. When disabling the server, the socket remains open. Therefore we cannot define the connection status without performing any operations.
Yes, for constant monitoring of connection status, we would have to use a separate thread and a separate connection

Post Reply