/// <summary> /// Adds a login to a database. /// </summary> /// <param name="login">A valid login name.</param> /// <param name="userName"></param> /// <returns>A SqlUser object.</returns> public SqlUser Add(string login, string userName) { // Validation if (login == null || login.Length == 0) { throw new ArgumentException(SR.GetString("SqlLogin_MustHaveValidName")); } if (this[login] != null) { throw new ArgumentException(String.Format(SR.GetString("SqlLogin_NameAlreadyExists"), login)); } // Physically add server NativeMethods.IUser dmoUser = (NativeMethods.IUser) new NativeMethods.User(); dmoUser.SetLogin(login); dmoUser.SetName(userName); this.database.dmoDatabase.GetUsers().Add(dmoUser); SqlUser user = new SqlUser(this.database, dmoUser.GetHasDBAccess(), dmoUser.GetLogin(), dmoUser.GetId(), dmoUser.GetName(), dmoUser.GetSystemObject()); user.dmoUser = dmoUser; this.sqlUsers.Add(user); return(user); }
/// <summary> /// Updates the SqlUserCollection with any changes made since the last call to Refresh. /// </summary> public void Refresh() { // Force internal refresh of users. database.dmoDatabase.GetUsers().Refresh(false); // Clear out old list this.sqlUsers = new ArrayList(); for (int i = 0; i < database.dmoDatabase.GetUsers().GetCount(); i++) { NativeMethods.IUser DmoUser = database.dmoDatabase.GetUsers().Item(i + 1); SqlUser user; if (DmoUser.GetSystemObject()) { user = new SqlUser(this.database, DmoUser.GetHasDBAccess(), DmoUser.GetLogin(), DmoUser.GetId(), DmoUser.GetName(), true); } else { user = new SqlUser(this.database, DmoUser.GetHasDBAccess(), DmoUser.GetLogin(), DmoUser.GetId(), DmoUser.GetName(), false); } this.sqlUsers.Add(user); user.dmoUser = DmoUser; user.Database = this.database; } }