I am having C# multi threading application and using MySQL with single connection to whole application. But when two or more thread try to access database at the same time, then i get below error :
There is already an open
DataReaderassociated with thisConnectionwhich must be closed first.
My Connection code is below
public static _connectionSetup = new MySqlConnection("Server=server ; Database=database;User ID=user;Password=pass;Pooling=true;");
and when i need to use connection i am using below code :-
using (MySqlConnection connection =_connectionSetup )
{
using (MySqlCommand command = new MySqlCommand("proc", connection))
{
....
}
}
I tried used pooling=true and i have create two separated connection as well for two different thread, but still i am getting above error.
Am I missing something?
How can I implement connection pool so that all thread will use separate connection and won't cause any issue?
usingand you're all done. stackoverflow.com/questions/9705637/…new MySqlConnection("Server=ser....is it ADO.NET? (Am i using ADO.net in above code ? i don't know ) and if i make_connectionSetupinstance variable then will connect again to database server or get connection from pool for second or further when i open connection using instance variable .Pooling=True;in the connection-string. But again, that's the default behaviour. To cut a long story short, pooling is enabled if you don't specifypooling=falsein the connection string.