Description:
When 'autogenerateschema' is on for the Membership- and Roleprovider it checks for version and whether to upgrade or not. That's fine.
But the way it does it, leads to unnessecary traffic.
File: SchemaManager.cs line: 93 looks like this:
private static int GetSchemaVersion(string connectionString)
{
// retrieve the current schema version
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
conn.Open();
string[] restrictions = new string[4];
restrictions[2] = "mysql_Membership";
DataTable dt = conn.GetSchema("Tables", restrictions);
if (dt.Rows.Count == 1)
return Convert.ToInt32(dt.Rows[0]["TABLE_COMMENT"]);
restrictions[2] = "my_aspnet_schemaversion";
dt = conn.GetSchema("Tables", restrictions);
if (dt.Rows.Count == 0) return 0;
MySqlCommand cmd = new MySqlCommand("SELECT * FROM my_aspnet_SchemaVersion", conn);
object ver = cmd.ExecuteScalar();
if (ver == null)
throw new ProviderException(Resources.MissingOrWrongSchema);
return (int)ver;
}
}
This code will normally go right through to the third call (except the one time, it upgrades from an old version). Waste of db calls.
I suggest the 3rd call is moved up front, like shown below, so it will normally only make one call to the db.
How to repeat:
You can try to set 'logging=true' in the connectionstring and watch the output window in VS (make sure you restart the asp.net application). You will see 3 calls just to get the version.
Suggested fix:
Change the code to:
private static int GetSchemaVersion(string connectionString)
{
// retrieve the current schema version
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
conn.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM my_aspnet_SchemaVersion", conn);
object ver = cmd.ExecuteScalar();
if (ver != null)
return (int)ver;
string[] restrictions = new string[4];
restrictions[2] = "mysql_Membership";
DataTable dt = conn.GetSchema("Tables", restrictions);
if (dt.Rows.Count == 1)
return Convert.ToInt32(dt.Rows[0]["TABLE_COMMENT"]);
restrictions[2] = "my_aspnet_schemaversion";
dt = conn.GetSchema("Tables", restrictions);
if (dt.Rows.Count == 0) return 0;
throw new ProviderException(Resources.MissingOrWrongSchema);
}
}
Description: When 'autogenerateschema' is on for the Membership- and Roleprovider it checks for version and whether to upgrade or not. That's fine. But the way it does it, leads to unnessecary traffic. File: SchemaManager.cs line: 93 looks like this: private static int GetSchemaVersion(string connectionString) { // retrieve the current schema version using (MySqlConnection conn = new MySqlConnection(connectionString)) { conn.Open(); string[] restrictions = new string[4]; restrictions[2] = "mysql_Membership"; DataTable dt = conn.GetSchema("Tables", restrictions); if (dt.Rows.Count == 1) return Convert.ToInt32(dt.Rows[0]["TABLE_COMMENT"]); restrictions[2] = "my_aspnet_schemaversion"; dt = conn.GetSchema("Tables", restrictions); if (dt.Rows.Count == 0) return 0; MySqlCommand cmd = new MySqlCommand("SELECT * FROM my_aspnet_SchemaVersion", conn); object ver = cmd.ExecuteScalar(); if (ver == null) throw new ProviderException(Resources.MissingOrWrongSchema); return (int)ver; } } This code will normally go right through to the third call (except the one time, it upgrades from an old version). Waste of db calls. I suggest the 3rd call is moved up front, like shown below, so it will normally only make one call to the db. How to repeat: You can try to set 'logging=true' in the connectionstring and watch the output window in VS (make sure you restart the asp.net application). You will see 3 calls just to get the version. Suggested fix: Change the code to: private static int GetSchemaVersion(string connectionString) { // retrieve the current schema version using (MySqlConnection conn = new MySqlConnection(connectionString)) { conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM my_aspnet_SchemaVersion", conn); object ver = cmd.ExecuteScalar(); if (ver != null) return (int)ver; string[] restrictions = new string[4]; restrictions[2] = "mysql_Membership"; DataTable dt = conn.GetSchema("Tables", restrictions); if (dt.Rows.Count == 1) return Convert.ToInt32(dt.Rows[0]["TABLE_COMMENT"]); restrictions[2] = "my_aspnet_schemaversion"; dt = conn.GetSchema("Tables", restrictions); if (dt.Rows.Count == 0) return 0; throw new ProviderException(Resources.MissingOrWrongSchema); } }