Version 6.4.4:
Using the most basic implementation of MySqlConnection, the following code takes 2-5 seconds per connection when preloading the connection pool to reach the "Min Pool Size" configured in my connection string.
Any ideas why it is taking so long, how to fix, or workarounds?
Connection String:
Code
private static void MySqlConnectionTester()
{
string connectionString = ConfigurationManager.ConnectionStrings["users"].ConnectionString;
using (var connection = new MySqlConnection(connectionString))
{
using (var command = connection.CreateCommand())
{
command.CommandText = "select * from users;";
try
{
connection.Open(); // This line hangs until "Min Pool Size" is reached.
using (var reader = command.ExecuteReader())
{
while(reader.Read())
{
// Read results
}
}
}
catch(Exception ex)
{
// Log exception
}
finally
{
connection.Close();
}
}
}
}
解决方案
At MySQL's homepage they write that you should avoid creating, opening and closing the connection object youself, instead you should use the helper class which should work better with connectionpooling.
I have not tested it, but was something I just read :)