Bug #52408 Exception and then internal reader is not closed
Submitted: 27 Mar 2010 14:47 Modified: 30 Mar 2010 5:28
Reporter: Pavel Bazanov Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.2, 6.3 OS:Any
Assigned to: CPU Architecture:Any

[27 Mar 2010 14:47] Pavel Bazanov
Description:
Hello,
I haven't written you anything for almost 2 months, so it's time :)

Just see the How to repeat section.

How to repeat:
public void Bug_52408()
{
	MySqlConnection conn = CreateAndOpenConnection();
	try
	{
		using (var command = new MySqlCommand("DROP TABLE IF EXISTS `boxes`", conn))
		{
			command.ExecuteNonQuery();

			command.CommandText =
				@"CREATE TABLE `boxes` 
				(
					`ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
					`BoxN` varchar(20) DEFAULT NULL,
					`InternalBoxN` int(11) DEFAULT '0',
					PRIMARY KEY (`ID`)
				) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"; ;
			command.ExecuteNonQuery();
		}

		try
		{
			using (var command = new MySqlCommand("SELECT InternalBoxN FROM boxes WHERE BoxN = 'END\\'", conn))
			{
				// ArgumentOutOfRangeException: Index and length must refer to a location within the string.
				// Parameter name: length
				command.ExecuteScalar();
			} // Internal reader is not closed on disposing command
		}
		catch (Exception ex)
		{
			Debug.WriteLine(ex.Message);
		}

		using (var command = new MySqlCommand("SELECT NOW()", conn))
		{
			command.ExecuteScalar();
			// MySqlException: There is already an open DataReader associated 
			// with this Connection which must be closed first.
		}
	}
	catch (Exception ex)
	{
		Debug.WriteLine(ex.Message);
	}
}
[29 Mar 2010 5:29] Tonci Grgin
Sure Pavel :) but I think this is a duplicate... Let me see.
[29 Mar 2010 7:14] Tonci Grgin
Pavel, I believe this is a duplicate of Bug#51610 and Bug#51788. What do you think? Is code from trunk working?
[29 Mar 2010 17:20] Pavel Bazanov
Hi Tonci,
Yes, it seems it's a duplicate of bug 51610. I am sorry, next time I will better check if it's a duplicate.

The code from trunk works fine, thank you.
[30 Mar 2010 5:28] Tonci Grgin
Pavel, you have definitely earned your right to be wrong occasionally :-) Main thing is, patch works.

Thank you for your good work!

Closed as duplicate of Bug#51610.