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
Reconnection?
Re: Reconnection?
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?
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?
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
-
- Fresh Boarder
- Posts: 8
- Joined: 12.07.2024, 16:16
Re: Reconnection?
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
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?
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.
- 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.
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
-
- Fresh Boarder
- Posts: 8
- Joined: 12.07.2024, 16:16
Re: Reconnection?
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Á
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Á
-
- Fresh Boarder
- Posts: 8
- Joined: 12.07.2024, 16:16
Re: Reconnection?
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 !
And it worked..!!!
Thank you very much !