Lost connections

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
jmarshall
Posts: 6
Joined: Tue 03 Oct 2006 14:24
Location: Australia

Lost connections

Post by jmarshall » Thu 19 Apr 2007 14:03

Greetings,

I am using MySqlDirect.Net 3.50.12 with the .Net Enterprise Library January 2006 and Visual Studio 2005.

When deployed onto the servers of my ISP, the system I have developed occasionally throws a Lost Connection exception from the CoreLab library.

It turns out that my ISP has configured their MySql servers to drop any connections that remain idle longer than 200 seconds. This tends to tie in with the exceptions being experienced.

This morning, I changed the connection string in web.config to turn off connection pooling and no exceptions have been generated since.

Obviously I would like to use connection pooling for performance but am not sure how to deal with the connections being forcefully killed from the MySql server.

Any thoughts on how to continue using connection pooling but avoid the lost connection exceptions?

Any help would be much appreciated.

Regards,
Justin.

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Fri 20 Apr 2007 07:35

You can check connections before using them each time with the Ping() method. If a connection is forcibly closed, you should re-open it again.

jmarshall
Posts: 6
Joined: Tue 03 Oct 2006 14:24
Location: Australia

Post by jmarshall » Fri 20 Apr 2007 08:29

Hi Alexey,

Thanks for the reply.

As I am using the Enterprise Library, typical code in this scenario does not deal with opening/closing connections, etc. All of that code is abstracted into the Enterprise Library.

Is there a place within the Enterprise Library style coding that I can perform the Ping and re-open the connection if it is closed? Perhaps I need to custom code the Enterprise Library?

Thanks,
Justin.

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Tue 24 Apr 2007 07:31

You can override virtual methods:
public virtual int ExecuteNonQuery(DbCommand command)
public virtual IDataReader ExecuteReader(DbCommand command)
public virtual object ExecuteScalar(DbCommand command)
and open connections as you need.

Post Reply