Connection timeout reason

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jmuehlenhoff
Posts: 36
Joined: Fri 30 Apr 2010 11:25

Connection timeout reason

Post by jmuehlenhoff » Thu 02 May 2013 10:09

Hi,

I have been wondering why connections to MySQL get closed after some period of idle time.

Is this due to some timeout setting on the MySQL server?

What is the best way to handle a "timeout based" disconnect? I know there is a OnConnectionLost event, but documentation is rather scarce on this subject.

Best regards.

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: Connection timeout reason

Post by DemetrionQ » Fri 10 May 2013 09:09

Hello.

There is a MySQL system variable - wait_timeout - it determines the number of seconds the server waits for activity on a noninteractive connection before closing it
http://dev.mysql.com/doc/refman/5.0/en/ ... it_timeout

To process connection lost you can handle the TMyConnection.OnConnectionLost event.
For that you should set the TMyConnection.Options.LocalFailover option to True.
TMyConnection.OnConnectionLost event handler has the RetryMode parameter that defines the behaviour after connection lost.

The additional information about using the OnConnectionLost event handler can be found in the article "Working in an Unstable Network" of the MyDAC documentation. Also you can find the description of the LocalFailover property, the OnConnectionLost event and the TRetryMode enumeration in the MyDAC documentation.

Also you can look at the example of handling the OnConnectionLost event in the Miscellaneous\FailOver demo.

jmuehlenhoff
Posts: 36
Joined: Fri 30 Apr 2010 11:25

Re: Connection timeout reason

Post by jmuehlenhoff » Fri 10 May 2013 09:14

Thank you, that's going to be helpful.

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: Connection timeout reason

Post by DemetrionQ » Tue 14 May 2013 10:38

If any other questions come up, please contact us.

Post Reply