07-08-2013, 06:52 PM
While coding the emulator i noticed that in case of a exception the mysql connection doesnt close in a try catch block.
And eventually will flood the connection pool.
I suggest to work like this
using(MySqlConnection dbConnerction = new MySqlConnection(strConnection))
{
dbConnerction.Open();
//executing a query
string query = "SELECT * FROM test_table";
MySqlCommand dbCommand = new MySqlCommand(query, dbConnerction);
MySqlDataReader dbReader = dbCommand.ExecuteReader();
//Reading the data
while (dbReader.Read()){
string stuff = dbReader["test_column1"].ToString();
float f= dbReader.GetFloat("test_column2");
}
}
This way everything inside the using block will always get disposed when leaving the using block.

