protected void Page_Load(object sender, System.EventArgs e)
        {
            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)));
            }

            SqlDatabaseCollection databases = server.Databases;

            server.Disconnect();

            // Create DataSet from list of databases
            DataSet ds = new DataSet();

            ds.Tables.Add();
            ds.Tables[0].Columns.Add("name");
            ds.Tables[0].Columns.Add("encodedname");
            ds.Tables[0].Columns.Add("size");
            for (int i = 0; i < databases.Count; i++)
            {
                SqlDatabase database = databases[i];
                ds.Tables[0].Rows.Add(new object[] { Server.HtmlEncode(database.Name), Server.UrlEncode(database.Name), database.Size == -1 ? "Unknown" : String.Format("{0}MB", database.Size) });
            }
            DatabasesDataGrid.DataSource = ds;
            DatabasesDataGrid.DataBind();
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlServer server = SqlServer.CurrentServer;

            server.Connect();
            SqlDatabaseCollection databases = server.Databases;

            server.Disconnect();

            // Create DataSet from list of databases
            DataSet ds = new DataSet();

            ds.Tables.Add();
            ds.Tables[0].Columns.Add("name");
            ds.Tables[0].Columns.Add("encodedname");
            ds.Tables[0].Columns.Add("size");
            for (int i = 0; i < databases.Count; i++)
            {
                SqlDatabase database = databases[i];
                ds.Tables[0].Rows.Add(new object[] { Server.HtmlEncode(database.Name), Server.UrlEncode(database.Name), database.Size == -1 ? "Unknown" : String.Format("{0}MB", database.Size) });
            }
            DatabasesDataGrid.DataSource = ds;
            DatabasesDataGrid.DataBind();
        }