Bug #13122 connection.state reporting incorrectly
Submitted: 12 Sep 2005 15:47 Modified: 6 Nov 2007 15:41
Reporter: Bill Keenan Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S4 (Feature request)
Version:1.5 OS:Windows (win xp)
Assigned to: CPU Architecture:Any

[12 Sep 2005 15:47] Bill Keenan
Description:
Well, it seems to me that Connection.State is not reliably correct. If I stop and start the mysql server, the state still reads as open, and throws 'connection reset' exceptions if i act on it.

So, I made a wrapper class, because the MysqlConnection class is sealed and I couldn't extend. Here it is for your benefit.

b.t.w. please let me know if i'm off base, or was using it incorrectly, or what have you.

---------
/*
 * User: bill@bigmojo.net
 * Date: 9/12/2005
 * Time: 11:16 AM
 *
 */

using System;
using System.Data;

using MySql.Data.MySqlClient;

namespace My.MySqlConnection
{

	
	/// <summary>
	/// Description of MySqlConnection.
	/// </summary>
	public class xmmsMySqlConnection:IDbConnection
	{
		private MySqlConnection _mysql = null;
	
		public xmmsMySqlConnection()
		{
			_mysql = new MySqlConnection();
		}
		
		#region IDbConnection Members
		
		
		
		public void ChangeDatabase(string databaseName)
			
		{
			
			_mysql.ChangeDatabase(Database);
			
		}
		
		
		
		public IDbTransaction BeginTransaction(System.Data.IsolationLevel il)
			
		{
			
			return _mysql.BeginTransaction(il);
			
		}
		
		
		
		IDbTransaction System.Data.IDbConnection.BeginTransaction()
			
		{
			
			return _mysql.BeginTransaction();
			
		}
		
		
		/// <summary>
		/// This is why we have this class, return results of ping, more reliable.
		/// </summary>
		public System.Data.ConnectionState State
			
		{
			
			get
				
			{
				
				if ( _mysql != null && _mysql.State != ConnectionState.Closed && _mysql.Ping()){
					return _mysql.State;
				}else{
					return ConnectionState.Closed;
				}
				
			}
			
		}
		
		
		
		public string ConnectionString
			
		{
			
			get
				
			{
				
				
				return _mysql.ConnectionString;
				
			}
			
			set
				
			{
				
				 _mysql.ConnectionString = value;
				
			}
			
		}
		
		
		
		public IDbCommand CreateCommand()
			
		{
			
			return _mysql.CreateCommand();
			
		}
		
		
		
		public void Open()
			
		{
			
			_mysql.Open();
			
		}
		
		
		
		public void Close()
			
		{
			
			_mysql.Close();
			
		}
		
		
		
		public string Database
			
		{
			
			get
				
			{
				
				return _mysql.Database;
				
			}
			
		}
		
		
		
		public int ConnectionTimeout
			
		{
			
			get
				
			{
				
				return _mysql.ConnectionTimeout;
				
			}
			
		}
		
		
		
		#endregion
		
		#region IDisposable Members
		
		
		
		public void Dispose()
			
		{
			
			_mysql.Dispose();
			
		}
		
		
		
		#endregion
	}
}
----------------

How to repeat:
start it all up

restart mysql server

try another query

Suggested fix:
well, im using ping instead..
[21 Sep 2005 10:39] Vasily Kishkin
Really MySqlConnection.State is not changed when mysqld had been dowloaded.
[21 Sep 2005 10:40] Vasily Kishkin
Sorry... I mean when mysqld had been shutdown.
[6 Nov 2007 15:41] Reggie Burnett
This is a duplicate of 13658 which is fixed.