Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / System.Web / System.Web.Security / SqlRoleProvider.cs
index 35f340f623d33215d7cbe0a457ad63da0d965b62..7c6fa45e89ffeaa399b0de88b88c49ddb1800073 100644 (file)
@@ -45,12 +45,16 @@ namespace System.Web.Security
        {
 
                string applicationName;
+               bool schemaIsOk = false;
 
                ConnectionStringSettings connectionString;
                DbProviderFactory factory;
 
                DbConnection CreateConnection ()
                {
+                       if (!schemaIsOk && !(schemaIsOk = AspNetDBSchemaChecker.CheckMembershipSchemaVersion (factory, connectionString.ConnectionString, "role manager", "1")))
+                               throw new ProviderException ("Incorrect ASP.NET DB Schema Version.");
+
                        DbConnection connection = factory.CreateConnection ();
                        connection.ConnectionString = connectionString.ConnectionString;
 
@@ -77,7 +81,7 @@ namespace System.Web.Security
                {
                        DbParameter dbp = command.CreateParameter ();
                        dbp.ParameterName = parameterName;
-                       dbp.Value = parameterValue = parameterValue;
+                       dbp.Value = parameterValue;
                        dbp.Direction = direction;
                        dbp.DbType = type;
                        command.Parameters.Add (dbp);
@@ -93,7 +97,7 @@ namespace System.Web.Security
                                        throw new ArgumentNullException ("null element in usernames array");
                                if (h.ContainsKey (u))
                                        throw new ArgumentException ("duplicate element in usernames array");
-                               if (u.Length == 0 || u.Length > 256 || u.IndexOf (",") != -1)
+                               if (u.Length == 0 || u.Length > 256 || u.IndexOf (',') != -1)
                                        throw new ArgumentException ("element in usernames array in illegal format");
                                h.Add (u, u);
                        }
@@ -104,7 +108,7 @@ namespace System.Web.Security
                                        throw new ArgumentNullException ("null element in rolenames array");
                                if (h.ContainsKey (r))
                                        throw new ArgumentException ("duplicate element in rolenames array");
-                               if (r.Length == 0 || r.Length > 256 || r.IndexOf (",") != -1)
+                               if (r.Length == 0 || r.Length > 256 || r.IndexOf (',') != -1)
                                        throw new ArgumentException ("element in rolenames array in illegal format");
                                h.Add (r, r);
                        } 
@@ -141,7 +145,7 @@ namespace System.Web.Security
                        if (rolename == null)
                                throw new ArgumentNullException ("rolename");
 
-                       if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (",") != -1)
+                       if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (',') != -1)
                                throw new ArgumentException ("rolename is in invalid format");
 
                        using (DbConnection connection = CreateConnection ()) {
@@ -169,7 +173,7 @@ namespace System.Web.Security
                        if (rolename == null)
                                throw new ArgumentNullException ("rolename");
 
-                       if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (",") != -1)
+                       if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf (',') != -1)
                                throw new ArgumentException ("rolename is in invalid format");
 
                        using (DbConnection connection = CreateConnection ()) {
@@ -189,7 +193,7 @@ namespace System.Web.Security
                                if (returnValue == 0)
                                        return true;
                                if (returnValue == 1)
-                                       return false; //role does not exists
+                                       return false; //role does not exist
                                else if (returnValue == 2 && throwOnPopulatedRole)
                                        throw new ProviderException (rolename + " is not empty");
                                else
@@ -203,7 +207,7 @@ namespace System.Web.Security
                                throw new ArgumentNullException ("roleName");
                        if (usernameToMatch == null)
                                throw new ArgumentNullException ("usernameToMatch");
-                       if (roleName.Length == 0 || roleName.Length > 256 || roleName.IndexOf (",") != -1)
+                       if (roleName.Length == 0 || roleName.Length > 256 || roleName.IndexOf (',') != -1)
                                throw new ArgumentException ("roleName is in invalid format");
                        if (usernameToMatch.Length == 0 || usernameToMatch.Length > 256)
                                throw new ArgumentException ("usernameToMatch is in invalid format");
@@ -356,7 +360,7 @@ namespace System.Web.Security
                                        throw new ArgumentNullException ("null element in usernames array");
                                if (h.ContainsKey (u))
                                        throw new ArgumentException ("duplicate element in usernames array");
-                               if (u.Length == 0 || u.Length > 256 || u.IndexOf (",") != -1)
+                               if (u.Length == 0 || u.Length > 256 || u.IndexOf (',') != -1)
                                        throw new ArgumentException ("element in usernames array in illegal format");
                                h.Add (u, u);
                        }
@@ -367,7 +371,7 @@ namespace System.Web.Security
                                        throw new ArgumentNullException ("null element in rolenames array");
                                if (h.ContainsKey (r))
                                        throw new ArgumentException ("duplicate element in rolenames array");
-                               if (r.Length == 0 || r.Length > 256 || r.IndexOf (",") != -1)
+                               if (r.Length == 0 || r.Length > 256 || r.IndexOf (',') != -1)
                                        throw new ArgumentException ("element in rolenames array in illegal format");
                                h.Add (r, r);
                        }