public static void AddDBUser(Database db, string dbusername) { // Map the user if (!DBChecks.DatabaseUserExists(db, dbusername)) { User dbuser = new User(db, dbusername); dbuser.Login = dbusername; dbuser.Create(); dbuser.Refresh(); } }
public static void DropDBUser(Database sourcedb, Database destdb, string dbusername) { foreach (DatabaseRole destrole in destdb.Roles) { string destrolename = destrole.Name; DatabaseRole sourcerole = sourcedb.Roles[destrolename]; if (!DBChecks.DBRoleExists(sourcedb, destrolename) && !sourcerole.EnumMembers().Contains(dbusername) && destrole.EnumMembers().Contains(dbusername)) { destrole.DropMember(dbusername); } } destdb.Users[dbusername].Drop(); }
public static void AddUserToDBRoles(Database sourcedb, Database destdb, string dbusername) { foreach (DatabaseRole role in sourcedb.Roles) { if (role.EnumMembers().Contains(dbusername)) { string rolename = role.Name; DatabaseRole destdbrole = destdb.Roles[rolename]; if (DBChecks.DBRoleExists(destdb, rolename) && dbusername != "dbo" && !destdbrole.EnumMembers().Contains(dbusername)) { destdbrole.AddMember(dbusername); destdbrole.Alter(); } } } }