Page 1 of 1

Lost connections

Posted: Thu 19 Apr 2007 14:03
by jmarshall
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.

Posted: Fri 20 Apr 2007 07:35
by Alexey
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.

Posted: Fri 20 Apr 2007 08:29
by jmarshall
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.

Posted: Tue 24 Apr 2007 07:31
by Alexey
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.