Description:
I use .NET Connector with ASP.NET 2.0 (C#) compiled uder VisualStudio 2005. When I repeat sequence of MySqlConnection.Open() and execute SELECT and MySqlConnection.Close() many times in one script page the pooling mechanism doesn't work. Open() always generate SHOW VARIABLES, SET NAMES and so on. Driver is always created again, is not pooled.
I have found error in the function NativeDriver.Ping() on line with ExecuteCommand(DBCmd.PING, null, 0), because the second parameter is declared as byte[] and required operation emitted exception "Array cannot be null.". This exception is in code of function Ping() refused and function returns false - pooling cannot work !
How to repeat:
Fragments of ASP.NET C# code:
...
public int GetSQLValue()
{
MySqlConnection conn = new MySqlConnection("...connection_string...");
conn.Open();
MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM tbl", conn);
int value = cmd.ExecuteScalar();
conn.Close();
return value;
}
...
Page ... On_Load(...)
{
...
for (int i = 0; i < 10; i++)
{
...
Response.Write(GetSQLValue().ToString);
...
}
...
}
******************************
Modification NativeDriver.cs - shows executed SQL commands:
added line:
System.Web.HttpContext.Current.Trace.Write("MySQL " + cmd.ToString(), Encoding.GetString(bytes, 0, length));
to function:
private void ExecuteCommand( DBCmd cmd, byte[] bytes, int length )