Page 1 of 1
Reconnection?
Posted: 14.07.2024, 01:36
by hffranzin1
When I lose connection for some reason, I can't get Zconnection to reconnect again...
I tried to use the onlost event but I was unsuccessful
can you help me ? I'm using PostgreSQL as a database and Zeos 8
Re: Reconnection?
Posted: 14.07.2024, 19:02
by aehimself
Hello,
Connection loss handling is working fine in Zeos with the protocols I'm using. Because of this, before I'll be able to say anything, you'll have to check:
- When are you trying to initiate the reconnection? What is the condition what makes your program think it lost contact?
- At this time what is the status of ZConnection.Connected?
- You mentioned that your attempts were "unsuccessful". Can you please explain what that means: what methods are you calling, what is happening, and of course if your receive any error messages?
Re: Reconnection?
Posted: 16.07.2024, 04:58
by hffranzin1
Hello,
It's certainly something I'm doing wrong, but I don't understand where...
Connected in a "normal" way
-- Zconnection.Connect;
However, when the network goes down, the following message comes back to me.
- The connection has not yet been opened Zeos
However, Zconnection is true connection
Re: Reconnection?
Posted: 16.07.2024, 11:10
by aehimself
The way Zeos handles and notifies the developer about connection losses are:
- An action which requires a trip to the database fails with EZSQLConnectionLost or EZDatabaseConnectionLostError
- There's an "OnLost" event handler on ZConnection which should fire off in an event like this
Zeos is not talking to the database without your knowledge and therefore has no way it can detect connection losses in the moment they happen. You will always be notified about connection losses on the next action which involves the RDBMS, let it be a simple .Ping, opening/executing a new query or just loading more data with dataset.Next.
The way my applications work is:
- I have a generic exception handler which in case EZSQLConnectionLost or EZDatabaseConnectionLostError was raised it triggers a reconnection
- There's also a timer which calls ZConnection.Ping once every minute. If it returns false it means connection is not alive -> trigger reconnection. The method can also throw EZUnsupportedException which means the protocol does not (yet) support ping -> disable the timer. It also can raise any other exceptions, which go in the generic exception handler, which reconnects if needed
Just with these two my program can keep an SQL connection alive and connected for hours or days, and reacts well to connection losses with MySQL, MSSQL and Oracle.
Re: Reconnection?
Posted: 17.07.2024, 15:27
by hffranzin1
Hello,
I understood, I set a 'Timer' running the ping, and the reconnection performed correctly, but it returns invalid characters...
In BeforeReconnect I forced the ClientCode to 'LATIN1' but I still wasn't successful
Example, return after reconnect
NOVA PETRÓPOLIS
MONTANHÃO
MAUÃ
The Correct
NOVA PETRÓPOLIS
MONTANHÃO
MAUÁ
Re: Reconnection?
Posted: 18.07.2024, 04:46
by hffranzin1
I found it, I was checking the postgresql configuration file, and the "enconding_client" line was commented out, I uncommented it and put LATIN1.
And it worked..!!!
Thank you very much !