Ejemplo n.º 1
0
        /// <summary>
        /// Adds a new SQL Server login
        /// </summary>
        /// <param name="name">The name for the new login</param>
        /// <param name="type">By default, a login is created for use by SQL Server Authentication. Alternately specify the login type to map a Microsoft Windows NT 4.0 or Microsoft Windows 2000 user or group.</param>
        /// <param name="password">The password.</param>
        /// <returns>A new SqlLogin Object</returns>
        public SqlLogin Add(string name, SqlLoginType type, string password)
        {
            // Validation
            if (name == null || name.Length == 0)
            {
                throw new ArgumentException(SR.GetString("SqlLogin_MustHaveValidName"));
            }

            if (this[name] != null)
            {
                throw new ArgumentException(String.Format(SR.GetString("SqlLogin_NameAlreadyExists"), name));
            }

            // Physically add server
            NativeMethods.ILogin dmoLogin = (NativeMethods.ILogin) new NativeMethods.Login();
            dmoLogin.SetName(name);
            dmoLogin.SetType((int)type);

            if (type == SqlLoginType.Standard)
            {
                dmoLogin.SetPassword(string.Empty, password);
            }

            this.server.dmoServer.GetLogins().Add(dmoLogin);

            SqlLogin login = new SqlLogin(this.server, dmoLogin.GetName(), (SqlLoginType)dmoLogin.GetType(), (SqlNtAccessType)dmoLogin.GetNTLoginAccessType(), dmoLogin.GetDatabase(), dmoLogin.GetLanguage(), dmoLogin.GetLanguageAlias());

            login.dmoLogin = dmoLogin;

            this.sqlLogins.Add(login);
            return(login);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// The SetPassword method changes the password for the referenced login.
 /// </summary>
 /// <param name="oldPassword"></param>
 /// <param name="newPassword"></param>
 public void SetPassword(string oldPassword, string newPassword)
 {
     dmoLogin.SetPassword(oldPassword, newPassword);
 }