How to handle lost connection

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
GEswin
Posts: 186
Joined: Wed 03 Nov 2004 16:57
Location: Spain
Contact:

How to handle lost connection

Post by GEswin » Tue 01 Feb 2005 09:24

Hi, I have an application that's running 24/7. From time to time i get a Lost connection to mysql (which is very strange to happen, server is always up and connected directly witha cross-over cable). How should I handle this problem, basically what i need is to reconnect instead of failing, but I can't go to each function and change to check connection, would there be any form for handling this from the tmyconnection ?

Thanks in advance,

J.Pieter Vos

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Tue 01 Feb 2005 10:46

Most probably, some of your queries is executed more than 30 seconds. Try to increase a value of CommandTimeout property.

Also possible that by any connection no command was executed for a long time. In this case MySQL Server itself can break a connection. Try to execute MyConnection.Ping once at some time or increase a value of appropriate server variable.

For more details about different reasons of this error occurrence please see MySQL Reference manual http://dev.mysql.com/doc/mysql/en/gone-away.html

GEswin
Posts: 186
Joined: Wed 03 Nov 2004 16:57
Location: Spain
Contact:

Post by GEswin » Tue 01 Feb 2005 14:47

All querys take less than 1 second to execute and get back results. I also disconnect upon it's finished and then connect back again. This is a small application for wireless terminals, using sockets. I create for each socket a new thread with a connection. This morning each onnection reported a Lost COnnection to mysql. On the same machine i have another program connected to the same server that didn't faill, and i checked the server itself and it has been up all time.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Wed 02 Feb 2005 08:23

What MyDAC version do you use? Do you use ConnectionPooling?

GEswin
Posts: 186
Joined: Wed 03 Nov 2004 16:57
Location: Spain
Contact:

Post by GEswin » Wed 02 Feb 2005 09:12

Latest version, and I don't use pooling.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Wed 02 Feb 2005 10:59

Do you use Direct mode or libmysql.dll? If the last one, what is its version?

Please specify if the occurrence of the error changes if to change TMyConnection.Options.Direct.

How many, roughly, queries are performed in a second within the same application? How many threads are used MyDAC on it?

GEswin
Posts: 186
Joined: Wed 03 Nov 2004 16:57
Location: Spain
Contact:

Post by GEswin » Thu 03 Feb 2005 13:34

Hi

I'm using direct mode only. As this application is in production and uses wireless terminals, it's for me difficult to try changes. There are max 8 terminals connected, each creates a thread with 3 tmyconnections (Two connections to same server but diferent DB, and one to another server). Normally there are 3 or 4 terminals connected, so max 4 threads, 12 connections in total. THe machine is connected directly with crossover cable to main server. All machines are big (For this app exclusive machine PIV 3 Ghz 800, 1 gb memory win 2003 server), server is dual xeon 2.8 ghz with 4 gb memory running suse 9.1). Mysql is v4.1.8 (Standart RPM official from mysql).

To main server there are about 10 workstations connected, all work with mysql and mydac never gives a connection loss.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Fri 04 Feb 2005 07:35

We still couldn't reproduce the problem.

At the average, how many calls to different servers are performed for a second within the same application?

Are there any regularities in error happening? For example, dependence on the number of threads? In general, how often does this error happen?

If you send us small complete sample to demonstrate the problem we could solve it faster.

Guest

Handling Lost Connections

Post by Guest » Wed 14 Sep 2005 16:35

I was interested in this thread, because I am looking at a similar issue, but for different reasons!

In my case, the application is connecting to a database server across ADSL and Internet connections, and there is a real possibility of the connection being broken. It would be good to be able to trap this and retry the connection rather than expecting the user to terminate the application and restart it...

GEswin
Posts: 186
Joined: Wed 03 Nov 2004 16:57
Location: Spain
Contact:

Post by GEswin » Wed 14 Sep 2005 21:29

Enclose the functions in Try..Except and best issues i've seen if it's some process you've to do from time to time, is just connect/do_the_job/disconnect. Right now i'm very happy and got no problems with mydac, and i have many appz working over adsl too.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Thu 15 Sep 2005 08:17

We think about MyDAC development in this direction. As a temporary
solution you can use MyDAC with MIDAS

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Post by swierzbicki » Fri 16 Sep 2005 06:15

I did the same. It works like a charm.
Enclose the functions in Try..Except

Post Reply