Ejemplo n.º 1
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SqlServer server = SqlServer.CurrentServer;
                server.Connect();

                SqlDatabase database = SqlDatabase.CurrentDatabase(server);

                Logins.DataSource = server.Logins;
                Logins.DataBind();


                // Remove existing users from the Logins selection
                foreach (SqlUser user in database.Users)
                {
                    ListItem item = Logins.Items.FindByValue(user.Login);
                    if (item != null)
                    {
                        Logins.Items.Remove(item);
                    }
                }

                if (Logins.Items.Count == 0)
                {
                    CreateButton.Enabled = false;
                    ErrorMessage.Text    = "All Logins are Users of this database.";
                }

                Username.Text = Logins.SelectedValue;

                server.Disconnect();
            }
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SqlServer server = SqlServer.CurrentServer;
                try
                {
                    server.Connect();
                }
                catch (System.Exception ex)
                {
                    //Response.Redirect("Error.aspx?errorPassCode=" + 2002);
                    Response.Redirect(String.Format("error.aspx?errormsg={0}&stacktrace={1}", Server.UrlEncode(ex.Message), Server.UrlEncode(ex.StackTrace)));
                }

                SqlDatabase database = SqlDatabase.CurrentDatabase(server);

                Logins.DataSource = server.Logins;
                Logins.DataBind();


                // Remove existing users from the Logins selection
                foreach (SqlUser user in database.Users)
                {
                    ListItem item = Logins.Items.FindByValue(user.Login);
                    if (item != null)
                    {
                        Logins.Items.Remove(item);
                    }
                }

                if (Logins.Items.Count == 0)
                {
                    CreateButton.Enabled = false;
                    ErrorMessage.Text    = "All Logins are Users of this database.";
                }

                Username.Text = Logins.SelectedValue;

                server.Disconnect();
            }
        }