From: Date: February 13 2008 8:17pm Subject: Connector/NET commit: r1176 - in branches/5.2: . MySql.Web/Providers MySql.Web/Providers/Properties MySql.Web/Providers/Source MySql.Web/Tests List-Archive: http://lists.mysql.com/commits/42237 X-Bug: 34495 Message-Id: <200802131917.m1DJHNsH005652@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/5.2/CHANGES branches/5.2/MySql.Web/Providers/MySql.Web.csproj branches/5.2/MySql.Web/Providers/Properties/Resources.resx branches/5.2/MySql.Web/Providers/Properties/schema2.sql branches/5.2/MySql.Web/Providers/Properties/schema3.sql branches/5.2/MySql.Web/Providers/Source/MembershipProvider.cs branches/5.2/MySql.Web/Providers/Source/ProfileProvider.cs branches/5.2/MySql.Web/Providers/Source/RoleProvider.cs branches/5.2/MySql.Web/Providers/Source/SchemaManager.cs branches/5.2/MySql.Web/Tests/MySql.Web.Tests.csproj Log: Bug #34495 MySQL MembershipProvider , RoleProvider, ProfileProvider Tons of fixes involving case, connections not being open, schema improvements, etc. Modified: branches/5.2/CHANGES =================================================================== --- branches/5.2/CHANGES 2008-02-12 18:10:15 UTC (rev 1175) +++ branches/5.2/CHANGES 2008-02-13 19:17:22 UTC (rev 1176) @@ -1,4 +1,4 @@ -Version 5.2 +Version 5.2 - 2/11/2008 . Added ClearPool and ClearAllPools features . DDEX provider now works under Visual Studio 2008 . Added support for DbDataAdapter UpdateBatchSize. Batching is fully supported @@ -12,7 +12,7 @@ . Added Allow User Variables connection string option so that users can use user variables without getting missing parameter exceptions -Version 5.1.5 - +Version 5.1.5 - 2/11/2008 - Fixed problem with membership provider where FindUserByEmail would fail trying to add a second parameter with the same name as the first (bug #33347) - Fixed long standing problem with compression over a network. It's now fast again. (bug #27865) Modified: branches/5.2/MySql.Web/Providers/MySql.Web.csproj =================================================================== --- branches/5.2/MySql.Web/Providers/MySql.Web.csproj 2008-02-12 18:10:15 UTC (rev 1175) +++ branches/5.2/MySql.Web/Providers/MySql.Web.csproj 2008-02-13 19:17:22 UTC (rev 1176) @@ -2,7 +2,7 @@ Debug AnyCPU - 8.0.50727 + 9.0.21022 2.0 {C28B1166-1380-445D-AEC1-8A18B990DD18} Library @@ -78,7 +78,7 @@ - + Modified: branches/5.2/MySql.Web/Providers/Properties/Resources.resx =================================================================== --- branches/5.2/MySql.Web/Providers/Properties/Resources.resx 2008-02-12 18:10:15 UTC (rev 1175) +++ branches/5.2/MySql.Web/Providers/Properties/Resources.resx 2008-02-13 19:17:22 UTC (rev 1176) @@ -117,9 +117,57 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Cannot delete a populated role. + Setting EnablePasswordRetrieval to true when PasswordFormat is Hashed is not supported. + + Cannot unencode a hashed password. + + + There was an error during membership provider initilization. + + + There was an error during role provider initilization. + + + There was an error during profile provider initilization. + + + There was an error resetting the password. + + + Incorrect password answer. + + + Invalid characters in user name. + + + Change password canceled due to New password validation failure. + + + Password answer required for password reset. + + + Reset password canceled due to password validation failure. + + + Password Reset is not enabled. + + + Password Retrieval Not Enabled. + + + Profile update failed. + + + Role name already exists. + + + Role name not found. + schema1.sql;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 @@ -130,4 +178,37 @@ schema3.sql;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + Unable to lock out user. + + + Unable to retrieve profile data from database. + + + Unable to update failure count. Membership database may be corrupt. + + + Unsupported password format. + + + User is already in role. + + + The supplied user is locked out. + + + Username not found. + + + User not in role. + + + Unable to initialize provider. Missing or incorrect schema. + + + Unable to create application. + + + Unable to create user. + \ No newline at end of file Modified: branches/5.2/MySql.Web/Providers/Properties/schema2.sql =================================================================== --- branches/5.2/MySql.Web/Providers/Properties/schema2.sql 2008-02-12 18:10:15 UTC (rev 1175) +++ branches/5.2/MySql.Web/Providers/Properties/schema2.sql 2008-02-13 19:17:22 UTC (rev 1176) @@ -1,7 +1,7 @@ ALTER TABLE mysql_Membership ADD PasswordKey char(32) AFTER Password, ADD PasswordFormat tinyint AFTER PasswordKey, - CHANGE email email VARCHAR(128), COMMENT='2'; + CHANGE Email Email VARCHAR(128), COMMENT='2'; \ No newline at end of file Modified: branches/5.2/MySql.Web/Providers/Properties/schema3.sql =================================================================== --- branches/5.2/MySql.Web/Providers/Properties/schema3.sql 2008-02-12 18:10:15 UTC (rev 1175) +++ branches/5.2/MySql.Web/Providers/Properties/schema3.sql 2008-02-13 19:17:22 UTC (rev 1176) @@ -2,32 +2,34 @@ /* create our application and user tables */ create table my_aspnet_Applications(id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(256), description VARCHAR(256)); -create table my_aspnet_Users(id INT PRIMARY KEY AUTO_INCREMENT, applicationId INT, name VARCHAR(256), isAnonymous TINYINT(1), lastActivityDate DATETIME); +create table my_aspnet_Users(id INT PRIMARY KEY AUTO_INCREMENT, + applicationId INT NOT NULL, name VARCHAR(256) NOT NULL, + isAnonymous TINYINT(1) NOT NULL DEFAULT 1, lastActivityDate DATETIME); create table my_aspnet_Profiles(userId INT PRIMARY KEY, valueindex longtext, stringdata longtext, binarydata longblob, lastUpdatedDate timestamp); create table my_aspnet_SchemaVersion(version INT); - + insert into my_aspnet_SchemaVersion VALUES (3); /* now we need to migrate all applications into our apps table */ -insert into my_aspnet_Applications (name) select ApplicationName from mysql_membership UNION select ApplicationName from mysql_UsersInRoles; +insert into my_aspnet_Applications (name) select ApplicationName from mysql_Membership UNION select ApplicationName from mysql_UsersInRoles; /* now we make our changes to the existing tables */ -alter table mysql_membership +alter table mysql_Membership rename to my_aspnet_Membership, drop primary key, drop column pkid, - drop column isonline, + drop column IsOnline, add column userId INT FIRST, add column applicationId INT AFTER userId; -alter table mysql_roles +alter table mysql_Roles rename to my_aspnet_Roles, - drop key rolename, + drop key Rolename, add column id INT PRIMARY KEY AUTO_INCREMENT FIRST, - add column applicationId INT AFTER id; + add column applicationId INT NOT NULL AFTER id; alter table mysql_UsersInRoles - drop key username, + drop key Username, rename to my_aspnet_UsersInRoles, add column userId INT FIRST, add column roleId INT AFTER userId, @@ -40,39 +42,40 @@ /* now merge our usernames into our users table */ insert into my_aspnet_Users (applicationId, name) - select applicationId, username from my_aspnet_membership - UNION select applicationId, username from my_aspnet_UsersInRoles; + select applicationId, Username from my_aspnet_Membership + UNION select applicationId, Username from my_aspnet_UsersInRoles; /* now set the user ids in our tables accordingly */ -update my_aspnet_Membership m, my_aspnet_Users u set m.userId = u.id where u.name=m.UserName AND u.applicationId=m.ApplicationId; -update my_aspnet_UsersInRoles r, my_aspnet_Users u set r.userId = u.id where u.name=r.UserName AND u.applicationId=r.applicationId; +update my_aspnet_Membership m, my_aspnet_Users u set m.userId = u.id where u.name=m.Username AND u.applicationId=m.applicationId; +update my_aspnet_UsersInRoles r, my_aspnet_Users u set r.userId = u.id where u.name=r.Username AND u.applicationId=r.applicationId; /* now update the isanonymous and last activity date fields for the users */ -update my_aspnet_users u, my_aspnet_membership m - set u.isAnonymous=0, u.lastActivityDate=m.lastActivityDate - where u.name = m.username; +update my_aspnet_Users u, my_aspnet_Membership m + set u.isAnonymous=0, u.lastActivityDate=m.LastActivityDate + where u.name = m.Username; /* make final changes to our tables */ alter table my_aspnet_Membership - drop column username, - drop column applicationName, + drop column Username, + drop column ApplicationName, drop column applicationId, add primary key (userId); /* next we set our role id values appropriately */ -update my_aspnet_UsersInRoles u, my_aspnet_Roles r set u.roleId = r.id where u.rolename = r.rolename and r.applicationId=u.applicationId; +update my_aspnet_UsersInRoles u, my_aspnet_Roles r set u.roleId = r.id where u.Rolename = r.Rolename and r.applicationId=u.applicationId; /* now we make the final changes to our roles tables */ alter table my_aspnet_Roles - drop column applicationName, - change column rolename name VARCHAR(255) NOT NULL; + drop column ApplicationName, + change column Rolename name VARCHAR(255) NOT NULL; alter table my_aspnet_UsersInRoles - drop column applicationName, + drop column ApplicationName, drop column applicationId, - drop column username, - drop column rolename, + drop column Username, + drop column Rolename, add primary key (userId, roleId); + \ No newline at end of file Modified: branches/5.2/MySql.Web/Providers/Source/MembershipProvider.cs =================================================================== --- branches/5.2/MySql.Web/Providers/Source/MembershipProvider.cs 2008-02-12 18:10:15 UTC (rev 1175) +++ branches/5.2/MySql.Web/Providers/Source/MembershipProvider.cs 2008-02-13 19:17:22 UTC (rev 1176) @@ -162,7 +162,7 @@ } catch (Exception ex) { - throw new ProviderException("There was an error during role provider initilization.", ex); + throw new ProviderException(Resources.ErrorInitOfMembershipProvider, ex); } } @@ -394,7 +394,7 @@ if (!(args.FailureInformation == null)) throw args.FailureInformation; else - throw new ProviderException("Change password canceled due to New password validation failure."); + throw new ProviderException(Resources.NewPasswordValidationFailed); } try @@ -528,8 +528,12 @@ connection.Open(); transaction = connection.BeginTransaction(); + // create or fetch a new application id + SchemaManager.CreateOrFetchApplicationId(applicationName, + ref applicationId, base.Description, connection); // either create a new user or fetch the existing user id - int userId = CreateOrFetchUserId(username, false, connection); + int userId = SchemaManager.CreateOrFetchUserId(connection, username, + applicationId, true); MySqlCommand cmd = new MySqlCommand( @"INSERT INTO my_aspnet_Membership @@ -688,7 +692,7 @@ public override string GetPassword(string username, string answer) { if (!EnablePasswordRetrieval) - throw new ProviderException("Password Retrieval Not Enabled."); + throw new ProviderException(Resources.PasswordRetrievalNotEnabled); try { @@ -700,8 +704,8 @@ if (-1 == userId) throw new ProviderException("Username not found."); - string sql = @"SELECT password, passwordAnswer, passwordKey, passwordFormat, - isLockedOut FROM my_aspnet_Membership WHERE userId=@userId"; + string sql = @"SELECT Password, PasswordAnswer, PasswordKey, PasswordFormat, + IsLockedOut FROM my_aspnet_Membership WHERE userId=@userId"; MySqlCommand cmd = new MySqlCommand(sql, connection); cmd.Parameters.AddWithValue("@userId", userId); @@ -709,19 +713,19 @@ { reader.Read(); if (reader.GetBoolean("IsLockedOut")) - throw new MembershipPasswordException("The supplied user is locked out."); + throw new MembershipPasswordException(Resources.UserIsLockedOut); - string password = reader.GetString("password"); - string passwordAnswer = reader.GetString("passwordAnswer"); - string passwordKey = reader.GetString("passwordKey"); + string password = reader.GetString("Password"); + string passwordAnswer = reader.GetString("PasswordAnswer"); + string passwordKey = reader.GetString("PasswordKey"); MembershipPasswordFormat format = (MembershipPasswordFormat) reader.GetInt32(3); if (RequiresQuestionAndAnswer && !(CheckPassword(answer, passwordAnswer, passwordKey, format))) { - UpdateFailureCount(userId, "passwordAnswer", connection); - throw new MembershipPasswordException("Incorrect password answer."); + UpdateFailureCount(userId, "PasswordAnswer", connection); + throw new MembershipPasswordException(Resources.IncorrectPasswordAnswer); } if (PasswordFormat == MembershipPasswordFormat.Encrypted) { @@ -793,7 +797,7 @@ if (userIsOnline) { cmd.CommandText = - @"UPDATE my_aspnet_Users SET LastActivityDate = @date WHERE id=@userId"; + @"UPDATE my_aspnet_Users SET lastActivityDate = @date WHERE id=@userId"; cmd.Parameters.AddWithValue("@date", DateTime.Now); cmd.ExecuteNonQuery(); @@ -877,7 +881,7 @@ string sql = @"SELECT u.name FROM my_aspnet_Users u JOIN my_aspnet_Membership m ON m.userid=u.id - WHERE m.email like @email AND u.applicationId=@appId"; + WHERE m.Email like @email AND u.applicationId=@appId"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@email", email); cmd.Parameters.AddWithValue("@appId", applicationId); @@ -901,7 +905,7 @@ public override string ResetPassword(string username, string answer) { if (!(EnablePasswordReset)) - throw new NotSupportedException("Password Reset is not enabled."); + throw new NotSupportedException(Resources.PasswordResetNotEnabled); try { @@ -912,12 +916,12 @@ // fetch the userid first int userId = GetUserId(connection, username); if (-1 == userId) - throw new ProviderException("Username not found."); + throw new ProviderException(Resources.UsernameNotFound); if (answer == null && RequiresQuestionAndAnswer) { - UpdateFailureCount(userId, "passwordAnswer", connection); - throw new ProviderException("Password answer required for password Reset."); + UpdateFailureCount(userId, "PasswordAnswer", connection); + throw new ProviderException(Resources.PasswordRequiredForReset); } string newPassword = Membership.GeneratePassword(newPasswordLength, MinRequiredNonAlphanumericCharacters); @@ -928,11 +932,11 @@ if (!(Args.FailureInformation == null)) throw Args.FailureInformation; else - throw new MembershipPasswordException("Reset password canceled due to password validation failure."); + throw new MembershipPasswordException(Resources.PasswordResetCanceledNotValid); } - MySqlCommand cmd = new MySqlCommand(@"SELECT passwordAnswer, - passwordKey, passwordFormat, IsLockedOut + MySqlCommand cmd = new MySqlCommand(@"SELECT PasswordAnswer, + PasswordKey, PasswordFormat, IsLockedOut FROM my_aspnet_Membership WHERE userId=@userId", connection); cmd.Parameters.AddWithValue("@userId", userId); @@ -942,18 +946,18 @@ { reader.Read(); if (reader.GetBoolean("IsLockedOut")) - throw new MembershipPasswordException("The supplied user is locked out."); + throw new MembershipPasswordException(Resources.UserIsLockedOut); - string passwordAnswer = reader.GetString("passwordAnswer"); - passwordKey = reader.GetString("passwordKey"); - format = (MembershipPasswordFormat)reader.GetByte("passwordFormat"); + string passwordAnswer = reader.GetString("PasswordAnswer"); + passwordKey = reader.GetString("PasswordKey"); + format = (MembershipPasswordFormat)reader.GetByte("PasswordFormat"); reader.Close(); if (RequiresQuestionAndAnswer && !CheckPassword(answer, passwordAnswer, passwordKey, format)) { - UpdateFailureCount(userId, "passwordAnswer", connection); - throw new MembershipPasswordException("Incorrect password answer."); + UpdateFailureCount(userId, "PasswordAnswer", connection); + throw new MembershipPasswordException(Resources.IncorrectPasswordAnswer); } } @@ -966,7 +970,7 @@ cmd.Parameters.AddWithValue("@lastPassChange", DateTime.Now); int rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected != 1) - throw new MembershipPasswordException("There was an error resetting the password."); + throw new MembershipPasswordException(Resources.ErrorResettingPassword); return newPassword; } } @@ -993,12 +997,12 @@ int userId = GetUserId(conn, user.UserName); if (-1 == userId) - throw new ProviderException("Username not found."); + throw new ProviderException(Resources.UsernameNotFound); string sql = @"UPDATE my_aspnet_Membership m, my_aspnet_Users u - SET m.email=@email, m.comment=@comment, m.isApproved=@isApproved, - m.lastLoginDate=@lastLoginDate, u.lastActivityDate=@lastActivityDate, - m.lastActivityDate=@lastActivityDate + SET m.Email=@email, m.Comment=@comment, m.IsApproved=@isApproved, + m.LastLoginDate=@lastLoginDate, u.lastActivityDate=@lastActivityDate, + m.LastActivityDate=@lastActivityDate WHERE m.userId=u.id AND u.name LIKE @name AND u.applicationId=@appId"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@Email", user.Email); @@ -1041,8 +1045,8 @@ int userId = GetUserId(connection, username); if (-1 == userId) return false; - string sql = @"SELECT password, passwordKey, passwordFormat, isApproved, - islockedout FROM my_aspnet_Membership WHERE userId=@userId"; + string sql = @"SELECT Password, PasswordKey, PasswordFormat, IsApproved, + Islockedout FROM my_aspnet_Membership WHERE userId=@userId"; MySqlCommand cmd = new MySqlCommand(sql, connection); cmd.Parameters.AddWithValue("@userId", userId); cmd.Parameters.AddWithValue("@appId", applicationId); @@ -1061,7 +1065,7 @@ reader.Close(); if (!CheckPassword(password, pwd, passwordKey, format)) - UpdateFailureCount(userId, "password", connection); + UpdateFailureCount(userId, "Password", connection); else if (isApproved) { isValid = true; @@ -1069,8 +1073,8 @@ MySqlCommand updateCmd = new MySqlCommand( @"UPDATE my_aspnet_Membership m, my_aspnet_Users u SET m.LastLoginDate = @lastLoginDate, u.lastActivityDate = @date, - m.lastActivityDate=@date - WHERE m.userid=@userid AND u.id=@userid", connection); + m.LastActivityDate=@date + WHERE m.userId=@userid AND u.id=@userid", connection); updateCmd.Parameters.AddWithValue("@lastLoginDate", currentDate); updateCmd.Parameters.AddWithValue("@date", currentDate); updateCmd.Parameters.AddWithValue("@userid", userId); @@ -1153,29 +1157,29 @@ string username = reader.GetString("name"); string email = null; - if (!reader.IsDBNull(reader.GetOrdinal("email"))) - email = reader.GetString("email"); + if (!reader.IsDBNull(reader.GetOrdinal("Email"))) + email = reader.GetString("Email"); string passwordQuestion = ""; - if (!(reader.GetValue(reader.GetOrdinal("passwordQuestion")) == DBNull.Value)) - passwordQuestion = reader.GetString("passwordQuestion"); + if (!(reader.GetValue(reader.GetOrdinal("PasswordQuestion")) == DBNull.Value)) + passwordQuestion = reader.GetString("PasswordQuestion"); string comment = ""; - if (!(reader.GetValue(reader.GetOrdinal("comment")) == DBNull.Value)) - comment = reader.GetString("comment"); + if (!(reader.GetValue(reader.GetOrdinal("Comment")) == DBNull.Value)) + comment = reader.GetString("Comment"); - bool isApproved = reader.GetBoolean("isApproved"); - bool isLockedOut = reader.GetBoolean("isLockedOut"); - DateTime creationDate = reader.GetDateTime("creationDate"); + bool isApproved = reader.GetBoolean("IsApproved"); + bool isLockedOut = reader.GetBoolean("IsLockedOut"); + DateTime creationDate = reader.GetDateTime("CreationDate"); DateTime lastLoginDate = new DateTime(); - if (!(reader.GetValue(reader.GetOrdinal("lastLoginDate")) == DBNull.Value)) - lastLoginDate = reader.GetDateTime("lastLoginDate"); + if (!(reader.GetValue(reader.GetOrdinal("LastLoginDate")) == DBNull.Value)) + lastLoginDate = reader.GetDateTime("LastLoginDate"); - DateTime lastActivityDate = reader.GetDateTime("lastActivityDate"); - DateTime lastPasswordChangedDate = reader.GetDateTime("lastPasswordChangedDate"); + DateTime lastActivityDate = reader.GetDateTime("LastActivityDate"); + DateTime lastPasswordChangedDate = reader.GetDateTime("LastPasswordChangedDate"); DateTime lastLockedOutDate = new DateTime(); - if (!(reader.GetValue(reader.GetOrdinal("lastLockedoutDate")) == DBNull.Value)) - lastLockedOutDate = reader.GetDateTime("lastLockedoutDate"); + if (!(reader.GetValue(reader.GetOrdinal("LastLockedoutDate")) == DBNull.Value)) + lastLockedOutDate = reader.GetDateTime("LastLockedoutDate"); MembershipUser u = new MembershipUser(Name, username, providerUserKey, email, passwordQuestion, comment, isApproved, @@ -1193,9 +1197,9 @@ return Encoding.Unicode.GetString( DecryptPassword(Convert.FromBase64String(password))); else if (format == MembershipPasswordFormat.Hashed) - throw new ProviderException("Cannot unencode a hashed password."); + throw new ProviderException(Resources.CannotUnencodeHashedPwd); else - throw new ProviderException("Unsupported password format."); + throw new ProviderException(Resources.UnsupportedPasswordFormat); } private string GetPasswordKey() @@ -1232,9 +1236,7 @@ return Convert.ToBase64String(hash.ComputeHash(keyedBytes)); } else - { - throw new ProviderException("Unsupported password format."); - } + throw new ProviderException(Resources.UnsupportedPasswordFormat); } private void UpdateFailureCount(int userId, string failureType, MySqlConnection connection) @@ -1253,15 +1255,15 @@ using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) { if (!reader.HasRows) - throw new ProviderException("Unable to update failure count. Membership database may be corrupt."); + throw new ProviderException(Resources.UnableToUpdateFailureCount); reader.Read(); - if (failureType == "password") + if (failureType == "Password") { failureCount = reader.GetInt32(0); windowStart = reader.GetDateTime(1); } - if (failureType == "passwordAnswer") + if (failureType == "PasswordAnswer") { failureCount = reader.GetInt32(2); windowStart = reader.GetDateTime(3); @@ -1271,7 +1273,7 @@ DateTime windowEnd = windowStart.AddMinutes(PasswordAttemptWindow); if (failureCount == 0 || DateTime.Now > windowEnd) { - if (failureType == "password") + if (failureType == "Password") { cmd.CommandText = @"UPDATE my_aspnet_Membership @@ -1279,7 +1281,7 @@ FailedPasswordAttemptWindowStart = @windowStart WHERE userId=@userId"; } - if (failureType == "passwordAnswer") + if (failureType == "PasswordAnswer") { cmd.CommandText = @"UPDATE my_aspnet_Membership @@ -1292,7 +1294,7 @@ cmd.Parameters.AddWithValue("@windowStart", DateTime.Now); cmd.Parameters.AddWithValue("@userId", userId); if (cmd.ExecuteNonQuery() < 0) - throw new ProviderException("Unable to update failure count and window start."); + throw new ProviderException(Resources.UnableToUpdateFailureCount); } else { @@ -1307,17 +1309,17 @@ cmd.Parameters.AddWithValue("@lastLockedOutDate", DateTime.Now); cmd.Parameters.AddWithValue("@userId", userId); if (cmd.ExecuteNonQuery() < 0) - throw new ProviderException("Unable to lock out user."); + throw new ProviderException(Resources.UnableToLockOutUser); } else { - if (failureType == "password") + if (failureType == "Password") { cmd.CommandText = @"UPDATE my_aspnet_Membership SET FailedPasswordAttemptCount = @count WHERE userId=@userId"; } - if (failureType == "passwordAnswer") + if (failureType == "PasswordAnswer") { cmd.CommandText = @"UPDATE my_aspnet_Membership @@ -1386,7 +1388,7 @@ } else if (email != null) { - sql += " AND m.email LIKE @email"; + sql += " AND m.Email LIKE @email"; cmd.Parameters.AddWithValue("@email", email); } sql += " ORDER BY u.id ASC LIMIT {0},{1}"; @@ -1411,23 +1413,7 @@ } } - private int CreateOrFetchUserId(string username, bool p, MySqlConnection connection) - { - MySqlCommand cmd = new MySqlCommand("SELECT id FROM my_aspnet_Users WHERE name=@name", connection); - cmd.Parameters.AddWithValue("@name", username); - object id = cmd.ExecuteScalar(); - if (id == null) - { - cmd.CommandText = "INSERT INTO my_aspnet_Users VALUES (NULL, @appId, @name, 0, NOW())"; - cmd.Parameters.AddWithValue("@appId", applicationId); - cmd.ExecuteNonQuery(); - cmd.CommandText = "SELECT LAST_INSERT_ID()"; - } - id = cmd.ExecuteScalar(); - return Convert.ToInt32(id); - } - #endregion } } Modified: branches/5.2/MySql.Web/Providers/Source/ProfileProvider.cs =================================================================== --- branches/5.2/MySql.Web/Providers/Source/ProfileProvider.cs 2008-02-12 18:10:15 UTC (rev 1175) +++ branches/5.2/MySql.Web/Providers/Source/ProfileProvider.cs 2008-02-13 19:17:22 UTC (rev 1176) @@ -38,6 +38,7 @@ using System.Transactions; using System.Web.Security; using MySql.Web.Common; +using MySql.Web.Properties; namespace MySql.Web.Profile { @@ -103,7 +104,7 @@ } catch (Exception ex) { - throw new ProviderException("There was an error during provider initilization.", ex); + throw new ProviderException(Resources.ErrorInitProfileProvider, ex); } } @@ -135,24 +136,24 @@ MySqlCommand queryCmd = new MySqlCommand( @"SELECT * FROM my_aspnet_Users WHERE applicationId=@appId AND - LastActivityDate < @lastActivityDate", + lastActivityDate < @lastActivityDate", c); queryCmd.Parameters.AddWithValue("@appId", applicationId); queryCmd.Parameters.AddWithValue("@lastActivityDate", userInactiveSinceDate); if (authenticationOption == ProfileAuthenticationOption.Anonymous) - queryCmd.CommandText += " AND IsAnonymous = 1"; + queryCmd.CommandText += " AND isAnonymous = 1"; else if (authenticationOption == ProfileAuthenticationOption.Authenticated) - queryCmd.CommandText += " AND IsAnonymous = 0"; + queryCmd.CommandText += " AND isAnonymous = 0"; MySqlCommand deleteCmd = new MySqlCommand( - "DELETE FROM my_aspnet_Profiles WHERE UserId = @userId", c); + "DELETE FROM my_aspnet_Profiles WHERE userId = @userId", c); deleteCmd.Parameters.Add("@userId", MySqlDbType.UInt64); List uidList = new List(); using (MySqlDataReader reader = queryCmd.ExecuteReader()) { while (reader.Read()) - uidList.Add(reader.GetUInt64("UserId")); + uidList.Add(reader.GetUInt64("userId")); } int count = 0; @@ -187,7 +188,7 @@ queryCmd.Parameters.Add("@name", MySqlDbType.VarChar); MySqlCommand deleteCmd = new MySqlCommand( - "DELETE FROM my_aspnet_Profiles WHERE UserId = @userId", c); + "DELETE FROM my_aspnet_Profiles WHERE userId = @userId", c); deleteCmd.Parameters.Add("@userId", MySqlDbType.UInt64); int count = 0; @@ -366,14 +367,14 @@ MySqlCommand queryCmd = new MySqlCommand( @"SELECT COUNT(*) FROM my_aspnet_Users WHERE applicationId = @appId AND - LastActivityDate < @lastActivityDate", + lastActivityDate < @lastActivityDate", c); queryCmd.Parameters.AddWithValue("@appId", applicationId); queryCmd.Parameters.AddWithValue("@lastActivityDate", userInactiveSinceDate); if (authenticationOption == ProfileAuthenticationOption.Anonymous) - queryCmd.CommandText += " AND IsAnonymous = 1"; + queryCmd.CommandText += " AND isAnonymous = 1"; else if (authenticationOption == ProfileAuthenticationOption.Authenticated) - queryCmd.CommandText += " AND IsAnonymous = 0"; + queryCmd.CommandText += " AND isAnonymous = 0"; return (int)queryCmd.ExecuteScalar(); } } @@ -430,7 +431,7 @@ } catch (Exception ex) { - throw new ProviderException("Unable to retrieve profile data from database.", ex); + throw new ProviderException(Resources.UnableToRetrieveProfileData, ex); } } @@ -457,8 +458,15 @@ using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); - int userId = CreateOrFetchUserId(connection, username, isAuthenticated); + // create or fetch a new application id + SchemaManager.CreateOrFetchApplicationId(applicationName, + ref applicationId, base.Description, connection); + + // either create a new user or fetch the existing user id + int userId = SchemaManager.CreateOrFetchUserId(connection, username, + applicationId, isAuthenticated); + MySqlCommand cmd = new MySqlCommand( @"INSERT INTO my_aspnet_Profiles VALUES (@userId, @index, @stringData, @binaryData, NULL) ON DUPLICATE KEY UPDATE @@ -471,14 +479,14 @@ cmd.Parameters.AddWithValue("@binaryData", binaryData); count = cmd.ExecuteNonQuery(); if (count != 1) - throw new Exception("Profile update operation affected zero rows."); + throw new Exception(Resources.ProfileUpdateFailed); ts.Complete(); } } } catch (Exception ex) { - throw new ProviderException("Unable to save profile data to database.", ex); + throw new ProviderException(Resources.ProfileUpdateFailed, ex); } } @@ -494,56 +502,6 @@ #region Private Methods - /// - /// It is assumed that this method is called from within a transaction or - /// a transactionscope - /// - /// - /// - /// - /// - private int CreateOrFetchUserId(MySqlConnection connection, string username, bool authenticated) - { - // first attempt to fetch an existing user id - MySqlCommand cmd = new MySqlCommand(@"SELECT id FROM my_aspnet_Users - WHERE applicationId = @appId AND name = @name", connection); - cmd.Parameters.AddWithValue("@appId", applicationId); - cmd.Parameters.AddWithValue("@name", username); - object userId = cmd.ExecuteScalar(); - if (userId != null) return (int)userId; - - // the user doesn't exist so we have to create one - int appId = CreateOrFetchApplicationId(connection); - - cmd.CommandText = @"INSERT INTO my_aspnet_Users VALUES (NULL, @appId, @name, @isAnon, Now())"; - cmd.Parameters[0].Value = appId; - cmd.Parameters.AddWithValue("@isAnon", !authenticated); - int recordsAffected = cmd.ExecuteNonQuery(); - if (recordsAffected != 1) - throw new ProviderException("Unable to create use for profile."); - - cmd.CommandText = "SELECT LAST_INSERT_ID()"; - return Convert.ToInt32(cmd.ExecuteScalar()); - } - - private int CreateOrFetchApplicationId(MySqlConnection connection) - { - if (applicationId != -1) - return applicationId; - MySqlCommand cmd = new MySqlCommand( - @"INSERT INTO my_aspnet_Applications VALUES (NULL, @appName, @appDesc)", - connection); - cmd.Parameters.AddWithValue("@appName", applicationName); - cmd.Parameters.AddWithValue("@appDesc", base.Description); - int recordsAffected = cmd.ExecuteNonQuery(); - if (recordsAffected != 1) - throw new ProviderException("Unable to create application for profile."); - - cmd.CommandText = "SELECT LAST_INSERT_ID()"; - applicationId = Convert.ToInt32(cmd.ExecuteScalar()); - return applicationId; - } - private void DecodeProfileData(DataRow profileRow, SettingsPropertyValueCollection values) { string indexData = (string)profileRow["valueindex"]; @@ -652,25 +610,25 @@ MySqlCommand cmd = new MySqlCommand( @"SELECT p.*, LENGTH(p.stringdata) + LENGTH(p.binarydata) AS profilesize, - u.UserName FROM my_aspnet_Profiles p - JOIN my_aspnet_Users u ON u.UserId = p.UserId + u.name FROM my_aspnet_Profiles p + JOIN my_aspnet_Users u ON u.id = p.userId WHERE u.applicationId = @appId", c); cmd.Parameters.AddWithValue("@appId", applicationId); if (usernameToMatch != null) { - cmd.CommandText += " AND u.UserName LIKE @userName"; + cmd.CommandText += " AND u.name LIKE @userName"; cmd.Parameters.AddWithValue("@userName", usernameToMatch); } if (userInactiveSinceDate != DateTime.MinValue) { - cmd.CommandText += " AND u.LastActivityDate < @lastActivityDate"; + cmd.CommandText += " AND u.lastActivityDate < @lastActivityDate"; cmd.Parameters.AddWithValue("@lastActivityDate", userInactiveSinceDate); } if (authenticationOption == ProfileAuthenticationOption.Anonymous) - cmd.CommandText += " AND u.IsAnonymous = 1"; + cmd.CommandText += " AND u.isAnonymous = 1"; else if (authenticationOption == ProfileAuthenticationOption.Authenticated) - cmd.CommandText += " AND u.IsAnonymous = 0"; + cmd.CommandText += " AND u.isAnonymous = 0"; cmd.CommandText += String.Format(" LIMIT {0},{1}", pageIndex * pageSize, pageSize); @@ -680,10 +638,10 @@ while (reader.Read()) { ProfileInfo pi = new ProfileInfo( - reader.GetString("UserName"), - reader.GetBoolean("IsAnonymous"), - reader.GetDateTime("LastActivityDate"), - reader.GetDateTime("LastUpdatdDate"), + reader.GetString("name"), + reader.GetBoolean("isAnonymous"), + reader.GetDateTime("lastActivityDate"), + reader.GetDateTime("lastUpdatdDate"), reader.GetInt32("profilesize")); pic.Add(pi); } Modified: branches/5.2/MySql.Web/Providers/Source/RoleProvider.cs =================================================================== --- branches/5.2/MySql.Web/Providers/Source/RoleProvider.cs 2008-02-12 18:10:15 UTC (rev 1175) +++ branches/5.2/MySql.Web/Providers/Source/RoleProvider.cs 2008-02-13 19:17:22 UTC (rev 1176) @@ -33,6 +33,7 @@ using System.Transactions; using System.Collections.Generic; using MySql.Web.Common; +using MySql.Web.Properties; namespace MySql.Web.Security { @@ -101,13 +102,17 @@ // now pre-cache the applicationId using (MySqlConnection conn = new MySqlConnection(connectionString)) { + conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT id FROM my_aspnet_Applications WHERE name=@name", conn); - applicationId = (int)cmd.ExecuteScalar(); + cmd.Parameters.AddWithValue("@name", applicationName); + object appId = cmd.ExecuteScalar(); + if (appId != null) + applicationId = Convert.ToInt32(appId); } } catch (Exception ex) { - throw new ProviderException("There was an error during role provider initilization.", ex); + throw new ProviderException(Resources.ErrorInitOfRoleProvider, ex); } } @@ -155,18 +160,18 @@ foreach (string rolename in rolenames) { if (!(RoleExists(rolename))) - throw new ProviderException("Role name not found."); + throw new ProviderException(Resources.RoleNameNotFound); } foreach (string username in usernames) { if (username.IndexOf(',') != -1) - throw new ArgumentException("User names cannot contain commas."); + throw new ArgumentException(Resources.InvalidCharactersInUserName); foreach (string rolename in rolenames) { if (IsUserInRole(username, rolename)) - throw new ProviderException("User is already in role."); + throw new ProviderException(Resources.UserIsAlreadyInRole); } } @@ -174,18 +179,19 @@ { using (TransactionScope ts = new TransactionScope()) { - using (MySqlConnection conn = new MySqlConnection(connectionString)) + using (MySqlConnection connection = new MySqlConnection(connectionString)) { + connection.Open(); MySqlCommand cmd = new MySqlCommand( - "INSERT INTO my_aspnet_UsersInRoles VALUES(@userId, @roleId)", conn); + "INSERT INTO my_aspnet_UsersInRoles VALUES(@userId, @roleId)", connection); cmd.Parameters.Add("@userId", MySqlDbType.Int32); cmd.Parameters.Add("@roleId", MySqlDbType.Int32); foreach (string username in usernames) { - int userId = GetUserId(conn, username); + int userId = GetUserId(connection, username); foreach (string rolename in rolenames) { - int roleId = GetRoleId(conn, rolename); + int roleId = GetRoleId(connection, rolename); cmd.Parameters[0].Value = userId; cmd.Parameters[1].Value = roleId; cmd.ExecuteNonQuery(); @@ -209,19 +215,24 @@ public override void CreateRole(string rolename) { if (rolename.IndexOf(',') != -1) - throw new ArgumentException("Role names cannot contain commas."); + throw new ArgumentException(Resources.InvalidCharactersInUserName); if (RoleExists(rolename)) - throw new ProviderException("Role name already exists."); + throw new ProviderException(Resources.RoleNameAlreadyExists); - using (MySqlConnection conn = new MySqlConnection(connectionString)) + using (MySqlConnection connection = new MySqlConnection(connectionString)) { - MySqlCommand cmd = - new MySqlCommand( - @"INSERT INTO my_aspnet_Roles Values(NULL, @name)", conn); - cmd.Parameters.AddWithValue("@name", rolename); try { - conn.Open(); + connection.Open(); + + // create or fetch a new application id + SchemaManager.CreateOrFetchApplicationId(applicationName, + ref applicationId, base.Description, connection); + + MySqlCommand cmd = new MySqlCommand( + @"INSERT INTO my_aspnet_Roles Values(NULL, @appId, @name)", connection); + cmd.Parameters.AddWithValue("@appId", applicationId); + cmd.Parameters.AddWithValue("@name", rolename); cmd.ExecuteNonQuery(); } catch (MySqlException e) @@ -245,18 +256,19 @@ { using (TransactionScope ts = new TransactionScope()) { - using (MySqlConnection conn = new MySqlConnection(connectionString)) + using (MySqlConnection connection = new MySqlConnection(connectionString)) { if (!(RoleExists(rolename))) - throw new ProviderException("Role does not exist."); + throw new ProviderException(Resources.RoleNameNotFound); if (throwOnPopulatedRole && GetUsersInRole(rolename).Length > 0) - throw new ProviderException("Cannot delete a populated role."); + throw new ProviderException(Resources.CannotDeleteAPopulatedRole); + connection.Open(); // first delete all the user/role mappings with that roleid MySqlCommand cmd = new MySqlCommand( @"DELETE uir FROM my_aspnet_UsersInRoles uir JOIN my_aspnet_Roles r ON uir.roleId=r.id - WHERE r.name LIKE @rolename AND r.applicationId=@appId", conn); + WHERE r.name LIKE @rolename AND r.applicationId=@appId", connection); cmd.Parameters.AddWithValue("@rolename", rolename); cmd.Parameters.AddWithValue("@appId", applicationId); cmd.ExecuteNonQuery(); @@ -285,9 +297,10 @@ /// public override string[] GetAllRoles() { - using (MySqlConnection conn = new MySqlConnection(connectionString)) + using (MySqlConnection connection = new MySqlConnection(connectionString)) { - return GetRolesByUserName(conn, null); + connection.Open(); + return GetRolesByUserName(connection, null); } } @@ -300,9 +313,10 @@ /// public override string[] GetRolesForUser(string username) { - using (MySqlConnection conn = new MySqlConnection(connectionString)) + using (MySqlConnection connection = new MySqlConnection(connectionString)) { - return GetRolesByUserName(conn, username); + connection.Open(); + return GetRolesByUserName(connection, username); } } @@ -318,14 +332,17 @@ try { - using (MySqlConnection conn = new MySqlConnection(connectionString)) + using (MySqlConnection connection = new MySqlConnection(connectionString)) { - int roleId = GetRoleId(conn, rolename); + connection.Open(); + int roleId = GetRoleId(connection, rolename); string sql = @"SELECT u.name FROM my_aspnet_Users u JOIN - my_aspnet_UsersInRoles uir ON uir.userid=u.id AND uir.roleid=@roleId + my_aspnet_UsersInRoles uir ON uir.userId=u.id AND uir.roleId=@roleId WHERE u.applicationId=@appId"; - MySqlCommand cmd = new MySqlCommand(sql, conn); + MySqlCommand cmd = new MySqlCommand(sql, connection); + cmd.Parameters.AddWithValue("@roleId", roleId); + cmd.Parameters.AddWithValue("@appId", applicationId); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) @@ -355,17 +372,18 @@ { try { - using (MySqlConnection conn = new MySqlConnection(connectionString)) + using (MySqlConnection connection = new MySqlConnection(connectionString)) { - conn.Open(); - string sql = @"SELECT COUNT(uir.*) FROM my_aspnet_UsersInRoles uir + connection.Open(); + string sql = @"SELECT COUNT(*) FROM my_aspnet_UsersInRoles uir JOIN my_aspnet_Users u ON uir.userId=u.id JOIN my_aspnet_Roles r ON uir.roleId=r.id WHERE u.name LIKE @userName AND r.name LIKE @roleName"; - MySqlCommand cmd = new MySqlCommand(sql, conn); + MySqlCommand cmd = new MySqlCommand(sql, connection); cmd.Parameters.AddWithValue("@userName", username); cmd.Parameters.AddWithValue("@roleName", rolename); - return (int)cmd.ExecuteScalar() > 0; + int count = Convert.ToInt32(cmd.ExecuteScalar()); + return count > 0; } } catch (Exception ex) @@ -386,7 +404,7 @@ foreach (string rolename in rolenames) { if (!(RoleExists(rolename))) - throw new ProviderException("Role name not found."); + throw new ProviderException(Resources.RoleNameNotFound); } foreach (string username in usernames) @@ -394,7 +412,7 @@ foreach (string rolename in rolenames) { if (!(IsUserInRole(username, rolename))) - throw new ProviderException("User is not in role."); + throw new ProviderException(Resources.UserNotInRole); } } @@ -402,16 +420,16 @@ { using (TransactionScope ts = new TransactionScope()) { - using (MySqlConnection conn = new MySqlConnection(connectionString)) + using (MySqlConnection connection = new MySqlConnection(connectionString)) { - conn.Open(); + connection.Open(); string sql = @"DELETE uir FROM my_aspnet_UsersInRoles uir JOIN my_aspnet_Users u ON uir.userId=u.id JOIN my_aspnet_Roles r ON uir.roleId=r.id WHERE u.name LIKE @username AND r.name LIKE @rolename AND u.applicationId=@appId AND r.applicationId=@appId"; - MySqlCommand cmd = new MySqlCommand(sql, conn); + MySqlCommand cmd = new MySqlCommand(sql, connection); cmd.Parameters.Add("@username", MySqlDbType.VarChar, 255); cmd.Parameters.Add("@rolename", MySqlDbType.VarChar, 255); cmd.Parameters.AddWithValue("@appId", applicationId); @@ -445,14 +463,16 @@ { try { - using (MySqlConnection conn = new MySqlConnection(connectionString)) + using (MySqlConnection connection = new MySqlConnection(connectionString)) { + connection.Open(); MySqlCommand cmd = new MySqlCommand( @"SELECT COUNT(*) FROM my_aspnet_Roles WHERE applicationId=@appId - AND name LIKE @name", conn); + AND name LIKE @name", connection); cmd.Parameters.AddWithValue("@appId", applicationId); cmd.Parameters.AddWithValue("@name", rolename); - return (int)cmd.ExecuteScalar() != 0; + int count = Convert.ToInt32(cmd.ExecuteScalar()); + return count != 0; } } catch (Exception ex) @@ -475,8 +495,10 @@ List users =new List(); try { - using (MySqlConnection conn = new MySqlConnection(connectionString)) + using (MySqlConnection connection = new MySqlConnection(connectionString)) { + connection.Open(); + string sql = @"SELECT u.name FROM my_aspnet_UsersInRole uir JOIN my_aspnet_Users u ON uir.userId=u.id JOIN my_aspnet_Roles r ON uir.roleId=r.id @@ -484,7 +506,7 @@ u.name LIKE @username AND u.applicationId=@appId"; - MySqlCommand cmd = new MySqlCommand(sql, conn); + MySqlCommand cmd = new MySqlCommand(sql, connection); cmd.Parameters.AddWithValue("@username", usernameToMatch); cmd.Parameters.AddWithValue("@rolename", rolename); cmd.Parameters.AddWithValue("@appId", applicationId); @@ -522,9 +544,9 @@ try { - string sql = "SELECT r.name FROM my_aspnet_roles r "; + string sql = "SELECT r.name FROM my_aspnet_Roles r "; if (username != null) - sql += "JOIN my_aspnet_usersinroles uir ON uir.roleId=r.id AND uir.userid=" + + sql += "JOIN my_aspnet_UsersInRoles uir ON uir.roleId=r.id AND uir.userId=" + GetUserId(connection, username); sql += " WHERE r.applicationId=@appId"; MySqlCommand cmd = new MySqlCommand(sql, connection); @@ -534,7 +556,7 @@ while (reader.Read()) roleList.Add(reader.GetString(0)); } - return roleList.ToArray(); + return (string[])roleList.ToArray(); } catch (Exception ex) { Modified: branches/5.2/MySql.Web/Providers/Source/SchemaManager.cs =================================================================== --- branches/5.2/MySql.Web/Providers/Source/SchemaManager.cs 2008-02-12 18:10:15 UTC (rev 1175) +++ branches/5.2/MySql.Web/Providers/Source/SchemaManager.cs 2008-02-13 19:17:22 UTC (rev 1176) @@ -29,6 +29,8 @@ using System.Configuration.Provider; using System.Resources; using System.IO; +using System.Diagnostics; +using MySql.Web.Properties; namespace MySql.Web.Common { @@ -58,12 +60,12 @@ if (config["autogenerateschema"] == "true") UpgradeToCurrent(connectionString, ver); else - throw new ProviderException("Unable to initialize provider. Missing or incorrect schema."); + throw new ProviderException(Resources.MissingOrWrongSchema); } catch (Exception ex) { - throw new ProviderException("Error during provider initialization.", ex); + throw new ProviderException(Resources.MissingOrWrongSchema, ex); } } @@ -108,9 +110,68 @@ MySqlCommand cmd = new MySqlCommand("SELECT * FROM my_aspnet_SchemaVersion", conn); object ver = cmd.ExecuteScalar(); if (ver == null) - throw new ProviderException("Schema corrupt"); + throw new ProviderException(Resources.MissingOrWrongSchema); return (int)ver; } } + + /// + /// Creates the or fetch user id. + /// + /// The connection. + /// The username. + /// The application id. + /// if set to true [authenticated]. + /// + internal static int CreateOrFetchUserId(MySqlConnection connection, string username, + int applicationId, bool authenticated) + { + Debug.Assert(applicationId > 0); + + // first attempt to fetch an existing user id + MySqlCommand cmd = new MySqlCommand(@"SELECT id FROM my_aspnet_Users + WHERE applicationId = @appId AND name = @name", connection); + cmd.Parameters.AddWithValue("@appId", applicationId); + cmd.Parameters.AddWithValue("@name", username); + object userId = cmd.ExecuteScalar(); + if (userId != null) return (int)userId; + + cmd.CommandText = @"INSERT INTO my_aspnet_Users VALUES + (NULL, @appId, @name, @isAnon, Now())"; + cmd.Parameters.AddWithValue("@isAnon", !authenticated); + int recordsAffected = cmd.ExecuteNonQuery(); + if (recordsAffected != 1) + throw new ProviderException(Resources.UnableToCreateUser); + + cmd.CommandText = "SELECT LAST_INSERT_ID()"; + return Convert.ToInt32(cmd.ExecuteScalar()); + } + + /// + /// Creates the or fetch application id. + /// + /// Name of the application. + /// The application id. + /// The application desc. + /// The connection. + internal static void CreateOrFetchApplicationId(string applicationName, + ref int applicationId, string applicationDesc, MySqlConnection connection) + { + // no need to create another one + if (applicationId > 0) return; + + MySqlCommand cmd = new MySqlCommand( + @"INSERT INTO my_aspnet_Applications VALUES (NULL, @appName, @appDesc)", + connection); + cmd.Parameters.AddWithValue("@appName", applicationName); + cmd.Parameters.AddWithValue("@appDesc", applicationDesc); + int recordsAffected = cmd.ExecuteNonQuery(); + if (recordsAffected != 1) + throw new ProviderException(Resources.UnableToCreateApplication); + + cmd.CommandText = "SELECT LAST_INSERT_ID()"; + applicationId = Convert.ToInt32(cmd.ExecuteScalar()); + } + } } \ No newline at end of file Modified: branches/5.2/MySql.Web/Tests/MySql.Web.Tests.csproj =================================================================== --- branches/5.2/MySql.Web/Tests/MySql.Web.Tests.csproj 2008-02-12 18:10:15 UTC (rev 1175) +++ branches/5.2/MySql.Web/Tests/MySql.Web.Tests.csproj 2008-02-13 19:17:22 UTC (rev 1176) @@ -33,7 +33,7 @@ 4 - +