internal static SqlConnectionHolder GetConnection(string connectionString, bool revertImpersonation) { connectionString.ToUpperInvariant(); SqlConnectionHolder sqlConnectionHolder = new SqlConnectionHolder(connectionString); bool flag = true; try { try { sqlConnectionHolder.Open(null, revertImpersonation); flag = false; } finally { if (flag) { sqlConnectionHolder.Close(); sqlConnectionHolder = null; } } } catch { throw; } return(sqlConnectionHolder); }
public override string[] GetAllRoles() { string[] result; try { SqlConnectionHolder sqlConnectionHolder = null; try { sqlConnectionHolder = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true); SqlCommand sqlCommand = new SqlCommand("dbo.aspnet_Roles_GetAllRoles", sqlConnectionHolder.Connection); StringCollection stringCollection = new StringCollection(); SqlParameter sqlParameter = new SqlParameter("@ReturnValue", SqlDbType.Int); SqlDataReader sqlDataReader = null; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandTimeout = this.CommandTimeout; sqlParameter.Direction = ParameterDirection.ReturnValue; sqlCommand.Parameters.Add(sqlParameter); try { sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess); while (sqlDataReader.Read()) { stringCollection.Add(sqlDataReader.GetString(0)); } } catch { throw; } finally { if (sqlDataReader != null) { sqlDataReader.Close(); } } string[] array = new string[stringCollection.Count]; stringCollection.CopyTo(array, 0); result = array; } finally { if (sqlConnectionHolder != null) { sqlConnectionHolder.Close(); sqlConnectionHolder = null; } } } catch { throw; } return(result); }
public override bool RoleExists(string roleName) { SecUtility.CheckParameter(ref roleName, true, true, true, 256, "roleName"); bool result; try { SqlConnectionHolder sqlConnectionHolder = null; try { sqlConnectionHolder = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true); SqlCommand sqlCommand = new SqlCommand("dbo.aspnet_Roles_RoleExists", sqlConnectionHolder.Connection); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandTimeout = this.CommandTimeout; SqlParameter sqlParameter = new SqlParameter("@ReturnValue", SqlDbType.Int); sqlParameter.Direction = ParameterDirection.ReturnValue; sqlCommand.Parameters.Add(sqlParameter); sqlCommand.Parameters.Add(this.CreateInputParam("@RoleName", SqlDbType.NVarChar, roleName)); sqlCommand.ExecuteNonQuery(); switch (this.GetReturnValue(sqlCommand)) { case 0: result = false; break; case 1: result = true; break; default: throw new ProviderException(SR.GetString("Stored procedure call failed.")); } } finally { if (sqlConnectionHolder != null) { sqlConnectionHolder.Close(); sqlConnectionHolder = null; } } } catch { throw; } return(result); }
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { SecUtility.CheckParameter(ref roleName, true, true, true, 256, "roleName"); bool result; try { SqlConnectionHolder sqlConnectionHolder = null; try { sqlConnectionHolder = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true); SqlCommand sqlCommand = new SqlCommand("dbo.aspnet_Roles_DeleteRole", sqlConnectionHolder.Connection); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandTimeout = this.CommandTimeout; SqlParameter sqlParameter = new SqlParameter("@ReturnValue", SqlDbType.Int); sqlParameter.Direction = ParameterDirection.ReturnValue; sqlCommand.Parameters.Add(sqlParameter); sqlCommand.Parameters.Add(this.CreateInputParam("@RoleName", SqlDbType.NVarChar, roleName)); sqlCommand.Parameters.Add(this.CreateInputParam("@DeleteOnlyIfRoleIsEmpty", SqlDbType.Bit, throwOnPopulatedRole ? 1 : 0)); sqlCommand.ExecuteNonQuery(); int returnValue = this.GetReturnValue(sqlCommand); if (returnValue == 2) { throw new ProviderException(SR.GetString("This role cannot be deleted because there are users present in it.")); } result = (returnValue == 0); } finally { if (sqlConnectionHolder != null) { sqlConnectionHolder.Close(); sqlConnectionHolder = null; } } } catch { throw; } return(result); }
public override string[] FindUsersInRole(string roleName, string usernameToMatch) { SecUtility.CheckParameter(ref roleName, true, true, true, 256, "roleName"); SecUtility.CheckParameter(ref usernameToMatch, true, true, false, 256, "usernameToMatch"); string[] result; try { SqlConnectionHolder sqlConnectionHolder = null; try { sqlConnectionHolder = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true); SqlCommand sqlCommand = new SqlCommand("dbo.aspnet_UsersInRoles_FindUsersInRole", sqlConnectionHolder.Connection); SqlDataReader sqlDataReader = null; SqlParameter sqlParameter = new SqlParameter("@ReturnValue", SqlDbType.Int); StringCollection stringCollection = new StringCollection(); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandTimeout = this.CommandTimeout; sqlParameter.Direction = ParameterDirection.ReturnValue; sqlCommand.Parameters.Add(sqlParameter); sqlCommand.Parameters.Add(this.CreateInputParam("@RoleName", SqlDbType.NVarChar, roleName)); sqlCommand.Parameters.Add(this.CreateInputParam("@UserNameToMatch", SqlDbType.NVarChar, usernameToMatch)); try { sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess); while (sqlDataReader.Read()) { stringCollection.Add(sqlDataReader.GetString(0)); } } catch { throw; } finally { if (sqlDataReader != null) { sqlDataReader.Close(); } } if (stringCollection.Count < 1) { switch (this.GetReturnValue(sqlCommand)) { case 0: result = new string[0]; break; case 1: throw new ProviderException(SR.GetString("The role '{0}' was not found.", roleName)); default: throw new ProviderException(SR.GetString("Stored procedure call failed.")); } } else { string[] array = new string[stringCollection.Count]; stringCollection.CopyTo(array, 0); result = array; } } finally { if (sqlConnectionHolder != null) { sqlConnectionHolder.Close(); sqlConnectionHolder = null; } } } catch { throw; } return(result); }
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { SecUtility.CheckArrayParameter(ref roleNames, true, true, true, 256, "roleNames"); SecUtility.CheckArrayParameter(ref usernames, true, true, true, 256, "usernames"); bool flag = false; try { SqlConnectionHolder sqlConnectionHolder = null; try { sqlConnectionHolder = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true); int i = usernames.Length; while (i > 0) { string text = usernames[usernames.Length - i]; i--; int num = usernames.Length - i; while (num < usernames.Length && text.Length + usernames[num].Length + 1 < 4000) { text = text + "," + usernames[num]; i--; num++; } int j = roleNames.Length; while (j > 0) { string text2 = roleNames[roleNames.Length - j]; j--; num = roleNames.Length - j; while (num < roleNames.Length && text2.Length + roleNames[num].Length + 1 < 4000) { text2 = text2 + "," + roleNames[num]; j--; num++; } if (!flag && (i > 0 || j > 0)) { new SqlCommand("BEGIN TRANSACTION", sqlConnectionHolder.Connection).ExecuteNonQuery(); flag = true; } this.RemoveUsersFromRolesCore(sqlConnectionHolder.Connection, text, text2); } } if (flag) { new SqlCommand("COMMIT TRANSACTION", sqlConnectionHolder.Connection).ExecuteNonQuery(); flag = false; } } catch { if (flag) { new SqlCommand("ROLLBACK TRANSACTION", sqlConnectionHolder.Connection).ExecuteNonQuery(); flag = false; } throw; } finally { if (sqlConnectionHolder != null) { sqlConnectionHolder.Close(); sqlConnectionHolder = null; } } } catch { throw; } }