[Lazarus] MariaDB gone away after long inactivities
Michael Van Canneyt
michael at freepascal.org
Tue Aug 18 08:53:47 CEST 2015
On Tue, 18 Aug 2015, Eric Kom wrote:
> Hi Folks,
> I got two procedures that are connected to MariaDB 5.6,
> My goal is if my application was launch for a long time, it must not lost the
> connection with my database and if the connection to the database was lost
> due to any reasons and restored (MariaDB running again), the procedure must
> still connect to the database without the application been restarted.
You must always be prepared to handle such error conditions.
The connection can go away for several reasons.
So, there is only one way to do what you want:
Catch errors, and analyse the error.
When the error indicates that the database connection was lost, re-initiate the connection.
There is a special connection.close(force) : if you set force to true,
it will ignore errors that occur during close (the error can happen if the connection was lost).
More information about the Lazarus