Bug #60570 Using multiple DataReader
Submitted: 21 Mar 2011 16:08 Modified: 21 Mar 2011 16:54
Reporter: Insiide MAN Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.3.6 OS:Any
Assigned to: CPU Architecture:Any

[21 Mar 2011 16:08] Insiide MAN
Description:
Hello,

When using a DataReader to browse the data on my first query, and that the holding of this first DataReader I want to make a second query I receive the following message:

There is already an open DataReader associated with this Connection which must be closed first.

This message appears beacause my fist DataReader is open yet when i do a seconde DataReader. See how to repeat for have an example.

Is that a solution exists ?

How to repeat:
string connStr = ConfigurationManager.ConnectionStrings["LocalMySqlServer"].ConnectionString;

mySqlConnection = new MySqlConnection(connStr);
mySqlConnection.Open();

MySqlCommand mySqlCommand = new MySqlCommand("", mySqlConnection);

mySqlCommand.CommandText = " SELECT * FROM clients ";

MySqlDataReader myReader;
myReader = mySqlCommand.ExecuteReader();

try
{

  while (myReader.Read())
  {

     String nom = myReader["nom"].ToString();

     MySqlCommand mySqlCommand2 = new MySqlCommand("", mySqlConnection);
     mySqlCommand2.CommandText = " SELECT * FROM clients ";
     MySqlDataReader myReader2;
     myReader2 = mySqlCommand2.ExecuteReader();

  }
}
finally
{
  myReader.Close();
}

Suggested fix:
Permit MultipleActiveResultSets=True in Connection string.
[21 Mar 2011 16:25] Valeriy Kravchuk
Please, read http://msdn.microsoft.com/en-us/library/haa3afyz%28v=vs.71%29.aspx:

"Note that while a DataReader is open, the Connection is in use exclusively by that DataReader. You will not be able to execute any commands for the Connection, including creating another DataReader, until the original DataReader is closed."
[21 Mar 2011 16:44] Insiide MAN
OK, so MultipleActiveResultSets is not available on MySql ?
[21 Mar 2011 16:54] Insiide MAN
I have found it's possible on SQL Server :

http://forums.mysql.com/read.php?38,160298,160461#msg-160461
[16 Mar 2012 14:30] Dan Rizzi
has this bug been fixed?