Recent

Author Topic: Auto reconnect to MySql database  (Read 761 times)

artem101

  • Jr. Member
  • **
  • Posts: 84
Auto reconnect to MySql database
« 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)

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

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