MadMyche is right - and the best solution is not to use a "shared" connection object, but to create it as required and Dispose it when you are finished. The simplest way to do that is in a
using
block:
using (MySqlConnection con = new MySqlConnection(strConnect))
{
con.Open();
using (MySqlCommand cmd = new MySqlCommand("SELECT Id, description FROM myTable", con))
{
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
int id = (int) reader["Id"];
string desc = (string) reader["description"];
Console.WriteLine("ID: {0}\n {1}", id, desc);
}
}
}
}
Do the same for every DB usage, and your problem goes away - even if you start multithreading later.