Lost connection to MySQL server during query

Lost connection to MySQL server during query

Postby jammerjam » Thu 26 Jun 2008 19:54

I've got 2 seperate VB.NET applications that are getting disconnected.

Code: Select all
App 1:
MyDirect.Net 4.3
MySQL 4.0.22 on server #1

Creates connection, executes SELECTs, DELETEs and INSERTS, closes connection.

Code: Select all
App 2:
MyDirect.Net 4.7
MySQL 4.0.22 AND MySQL 5.0 on server #2

Creates connection, pulls 1000 records into a data reader and loops through, closes connection.

In both instances the connection will break at ~30 seconds reliably. App 2 was tested against 2 different versions of MySQL...and broke both times.

Code: Select all
Connection String attempts:
SERVER=server;PORT=3306;DATABASE=Test;USER=root;PASSWORD=SECRET;Pooling=true;Max Pool Size=3;Connection Timeout=10;
SERVER=server;PORT=3306;DATABASE=Test;USER=root;PASSWORD=SECRET;Pooling=false;Max Pool Size=3;Connection Timeout=10;
SERVER=server;PORT=3306;DATABASE=Test;USER=root;PASSWORD=SECRET;Pooling=true;Max Pool Size=3;Connection Timeout=100;

As seen above I tried numerous connection strings to get this to work. Unfortunately I cannot copy & paste actual code, and the apps themselves are fairly complex.

I've even attempted to Ping() the connection before App #2 reads each record but that didn't help. I also am attempting to Ping() the connection before Open() it.

Posts: 27
Joined: Wed 09 Jan 2008 22:56

Postby pleb » Thu 26 Jun 2008 22:34

do you get an error message? if so what is it?

Check to make sure you're closing the connections properly.

Test the network by running a few queries in a product like MyDeveloper or MySQL Query Browser and see if they also error. If they do it's probably a problem to do with the network, such as firewall, routing rules, etc...
Posts: 37
Joined: Mon 23 Jun 2008 06:21
Location: Melbourne, Australia

Postby Alexey.mdr » Fri 27 Jun 2008 11:13


Firstly, as pleb has already mentioned above, the exception message is quite important.
Secondly, when you use pooling try increasing the max pool size property, or just omit it (the default value is 100)
Code: Select all
Pooling=true;Max Pool Size=3;
Does it make sense?

P.S.: there is no need of max pool size property set when you do not use pooling.
Code: Select all
Pooling=false;Max Pool Size=3;

Posts: 729
Joined: Thu 13 Dec 2007 10:24

Postby jammerjam » Fri 27 Jun 2008 12:41

The error is: Lost connection to MySQL server during query

All connections are closed but when I run the app it's not even getting that far. Here's what it does:
Code: Select all
1.  Open connection
2.  Run a select command and return data reader
3.  Iterate through data reader
4.  After 30 seconds - get error:  Lost connection to MySQL server during query
5.  In finally block close connection.
6.  Done.

I tried setting the max pool size back to 100 and that didn't affect anything. The commands work fine in MySQL Query Browser.
Posts: 27
Joined: Wed 09 Jan 2008 22:56

Postby pleb » Fri 27 Jun 2008 13:12

Hi jammerjam,

I have a few ideas...

Could you post your connection string (minus username, password, ip address) ;)

Is this your server? Maybe a hosting account of some sort? Possibly going through a VPN?

Is it code execution getting to the iterate through results stage?

Does the server have some type of script that runs to kill long running queries? (MySQL can't do this by default, but cron + bored sys admin can) Instead of logging long running queries some admins like to kill them.

Regards Pleb
Posts: 37
Joined: Mon 23 Jun 2008 06:21
Location: Melbourne, Australia

Postby anton.connect » Tue 01 Jul 2008 08:52

jammerjam, have you solved your problem? Please let me know.
Posts: 43
Joined: Thu 19 Jun 2008 14:30

Postby itcore@vit.ch » Fri 19 Sep 2008 13:55

I had the same problem. Originally I defined the datacontext as a static member variable and run it on IIS. I just had to make a non-static member.
Last edited by itcore@vit.ch on Thu 17 Feb 2011 05:20, edited 1 time in total.
Posts: 43
Joined: Wed 17 Sep 2008 11:31

Postby Shalex » Wed 24 Sep 2008 10:00

Please specify more clearly the problem. What is the text of the error? What are the steps we should take to reproduce it? Could you please send me (alexsh at devart.com) a test project and the script that creates the tables and fills them with data?
Devart Team
Posts: 7893
Joined: Thu 14 Aug 2008 12:44

Return to dotConnect for MySQL