Lazarus

Programming => Databases => Topic started by: artem101 on September 19, 2020, 03:51:34 pm

Title: Auto reconnect to MySql database
Post by: artem101 on September 19, 2020, 03:51:34 pm
Hello all!

I`m making program working with MySql database. It may works for a long time without any activity and sometimes connection may be closed by server with wait timeout.

I created some demo with trying to implement automatic reconnect feature before data has been send to the server. I forcibly set the mysql variable 'set_timeout' to 10 seconds. In SQLQuery`s BeforeDelete and BeforeEdit events I check status of current connection and if it closed, create it again.

Issue is that insert and update don`t work after reconnect.
Insert error:
(https://i.ibb.co/MPgt0kZ/20200919-163331.png) (https://ibb.co/7rSZmtj)

Update error:
(https://i.ibb.co/1f1QcxP/20200919-163354.png) (https://ibb.co/27xhJBC)

If connection is still alive, these actions forks fine.

Versions:
Lazarus: 1.6, FPC: 3.0.0, OS: Windows 7 64 bit
TinyPortal © 2005-2018