Need help managing MySql connections
- by David Jenings
I'm having trouble finding a clear explanation of connection pooling. I'm building an app using the .NET connector I downloaded from mysql.com. The app only needs one db connection but will be running simultaneously on about 6 machines on my network. Normally, I'd create the connection at startup and just leave it. But I'm seeing lots of posts from people who say that's bad practice. Also I'm concerned about timeouts. My app will run 24/7 and there may be extended periods without database activity.
I'm leaning toward the following:
using (MySqlConnection conn = new MySqlConnection(connStr))
{
conn.Open();
// use connection
}
But I'm not sure I understand what's going on in the background. Is this actually closing the connection and allowing gc to kill the object, or is there a built in pooling behavior that preserves the object and redelivers it the next time I try to create one?
I certainly don't want the app reauthenticating across the network every time I hit the database.
Can anyone offer me some advise?