using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Text; namespace MySqlStateChangeBug { class Program { static void Main(string[] Args) { try { MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection("Data Source=localhost; Database=db; User Id=uid; Password=pwd;"); conn.StateChange += new StateChangeEventHandler(MonitorChange); conn.Open(); conn.Close(); } catch(Exception ex) { Console.WriteLine("Exception Caught:"); Console.WriteLine(ex.ToString()); } Console.WriteLine("Press any key to exit."); Console.ReadKey(true); } static void MonitorChange(Object Sender, StateChangeEventArgs Args) { if(Sender is DbConnection) { DbConnection conn = (DbConnection)Sender; if(Args.CurrentState==ConnectionState.Open) { System.Diagnostics.Trace.WriteLine("Args.CurrentState = " + Args.CurrentState); System.Diagnostics.Trace.WriteLine("conn.State = " + conn.State); DbCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT 1"; object result = cmd.ExecuteScalar(); System.Diagnostics.Trace.WriteLine("result = " + result); } } } } }