Saturday, October 20, 2007
« Scrum Lovers | Main | Radiohead New Album "In Rainbows" - Sell... »

I've stumbled upon (what appears to be) a bug in MySQL .Net Connector (version 5.1.3).
I opened the bug in the MySQL bugs database, you can read the details here - bug #31617.

Basically, when calling MySqlCommand.ExecuteReader with an sql statement that times out - you get back a closed MySqlDataReader and the underlying MySqlConnection becomes corrupted, meaning you cannot use it for new operations and you cannot close it either.

The workaround you can implement in the meanwhile is:

1. Always check that the reader you got is open before iterating on it:

using(MySqlDataReader reader = command.ExecuteReader())
{
  if(!reader.IsClosed())
  //use reader
}


2. "Fix" the connection by forcefully setting the problematic field using reflection:
  //if we got a closed reader from MySqlCommand.ExecuteReader, need to set the Reader property of connection to null
  PropertyInfo p = connection.GetType().GetProperty("Reader", BindingFlags.NonPublic | BindingFlags.Instance);
  p.SetValue(connection, null, null);



More on MySQL at pashabitz.com:
MySQL dates quiz
MySQL dates answer

Want to join me as partner in a cool new startup?
Get in touch: pasha at cohai dot co

Bookmark and Share Saturday, October 20, 2007 10:55:38 PM (Jerusalem Standard Time, UTC+02:00)  #    Comments [4]  
Saturday, April 16, 2011 8:49:02 PM (Jerusalem Daylight Time, UTC+03:00)
YMMD with that asnewr! TX
Monday, April 18, 2011 3:09:46 AM (Jerusalem Daylight Time, UTC+03:00)
VYOS7S , [url=http://ktcnsywdpyis.com/]ktcnsywdpyis[/url], [link=http://crjshehajuqm.com/]crjshehajuqm[/link], http://eqlvurdrmsmu.com/
Saturday, April 23, 2011 7:31:18 PM (Jerusalem Daylight Time, UTC+03:00)
opFMw7 <a href="http://rycvdloszdnq.com/">rycvdloszdnq</a>
Monday, April 25, 2011 12:39:21 AM (Jerusalem Daylight Time, UTC+03:00)
rEPrAG , [url=http://libljlkqgpmr.com/]libljlkqgpmr[/url], [link=http://tjueqnimoglq.com/]tjueqnimoglq[/link], http://kpwuvyjuwlug.com/
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):