Lost connections

Lost connections

Postby 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.
jmarshall
 
Posts: 6
Joined: Tue 03 Oct 2006 14:24
Location: Australia

Postby 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.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby 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.
jmarshall
 
Posts: 6
Joined: Tue 03 Oct 2006 14:24
Location: Australia

Postby 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.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL