Bug #30964 StateChange imperfection
Submitted: 12 Sep 2007 5:35 Modified: 13 Nov 2007 11:36
Reporter: Jared S (Silver Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.0.8 OS:Windows (Any)
Assigned to: CPU Architecture:Any
Tags: connect, statechange

[12 Sep 2007 5:35] Jared S
Description:
Hi,

If a DataReader is executed from within _StateChange event as soon as the connection is open, MySQL.Data.DLL will throw Null Exception.

Obvisouly the best thing for me to do is to move my DataReader outside of the event and call directly after .Connect.

However, an exception is an exception, and if it was my source code I would remove it.

VB has great 'Optional' parameter syntax, however I am getting out of my depth here and have very little knowledge of C# and MySql.Data.dll.

Maybe if you have nothing else to program on NET connector, you can investigate.

How to repeat:
private static void CON0_StateChange(object sender, System.Data.StateChangeEventArgs e)
{
if (e.CurrentState == System.Data.ConnectionState.Open)
{
CMD0 = new MySql.Data.MySqlClient.MySqlCommand("show databases", CON0);
DTR0 = CMD0.ExecuteReader();
}
}

Suggested fix:
connection.cs [line 355] : SetState(..) -needs and optional param called IgnoreRaiseEvent
connection.cs [line 408] : SetState(ConnectionState.Open, True);
connection.cs [line 426] : this.OnStateChange(new StateChangeEventArgs(oldConnectionState, this.connectionState));

..And then

connection.cs [line 372] : SetState(ConnectionState.Closed, False);
connection.cs [line 382] : SetState(ConnectionState.Connecting, False);
connection.cs [line 400] : SetState(ConnectionState.Closed, False);
connection.cs [line 485] : SetState(ConnectionState.Closed, False);
connection.cs [line 510] : SetState(ConnectionState.Closed, False);
[12 Sep 2007 5:37] Jared S
Pic of inner workings

Attachment: StateChange.jpg (image/pjpeg, text), 236.68 KiB.

[21 Sep 2007 22:22] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/34469
[21 Sep 2007 22:23] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/34470
[21 Sep 2007 22:24] Reggie Burnett
Fixed in 1.0.11, 5.0.9, 5.1.4, and 5.2+
[21 Sep 2007 22:28] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/34471
[13 Nov 2007 11:36] MC Brown
A note has been added to the 1.0.11, 5.0.9, 5.1.4 and 5.2.0 changelogs: 

Commands executed from within the state change handeler would fail with a NULL exception