示例#1
0
        /// <summary>
        /// Updates the SqlLoginCollection  with any changes made since the last call to Refresh.
        /// Refresh is automatically called once when the SqlTable.sqlLogins collection is read.
        /// </summary>
        public void Refresh()
        {
            server.dmoServer.GetLogins().Refresh(false);
            sqlLogins = new ArrayList();

            for (int i = 0; i < server.dmoServer.GetLogins().GetCount(); i++)
            {
                SqlLogin             login;
                NativeMethods.ILogin dmoLogin = null;
                dmoLogin = server.dmoServer.GetLogins().Item(i + 1);

                SqlLoginType    type    = (SqlLoginType)dmoLogin.GetType();
                SqlNtAccessType ntlogin = (SqlNtAccessType)dmoLogin.GetNTLoginAccessType();

                login = new SqlLogin(this.server, dmoLogin.GetName(), type, ntlogin, dmoLogin.GetDatabase(), dmoLogin.GetLanguage(), dmoLogin.GetLanguageAlias());

                sqlLogins.Add(login);

                login.dmoLogin = dmoLogin;
            }
        }
示例#2
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);
        }