Exemple #1
0
        public override DataTable Clone()
        {
            ServerSizeSummary cln = ((ServerSizeSummary)(base.Clone()));

            cln.InitVars();
            return(cln);
        }
Exemple #2
0
 internal ServerSizeSummaryRow(DataRowBuilder rb) : base(rb)
 {
     this.tableServerSizeSummary = ((ServerSizeSummary)(this.Table));
 }
Exemple #3
0
        private static void AddDatabaseCreateDate(ref ServerSizeSummary sizeSummary, ConnectionData connData)
        {
            string sql2000Cmd = "SELECT name, crdate FROM sysdatabases";
            string sql2005Cmd = "SELECT name, create_date FROM sys.databases";
            string filter;

            connData.DatabaseName = "master";
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = SqlSync.Connection.ConnectionHelper.GetConnection(connData);
            cmd.CommandType = CommandType.Text;
            try
            {
                if (cmd.Connection.State == ConnectionState.Closed)
                {
                    cmd.Connection.Open();
                }

                try
                {
                    cmd.CommandText = sql2005Cmd;
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            filter = sizeSummary.DatabaseNameColumn.ColumnName + "='" + reader[0].ToString() + "'";
                            if (sizeSummary.Select(filter).Length > 0)
                            {
                                ((ServerSizeSummaryRow)sizeSummary.Select(filter)[0]).DateCreated = reader.GetDateTime(1);
                            }
                        }
                    }
                }
                catch
                {
                    try
                    {
                        cmd.CommandText = sql2000Cmd;
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                filter = sizeSummary.DatabaseNameColumn.ColumnName + "='" + reader[0].ToString() + "'";
                                if (sizeSummary.Select(filter).Length > 0)
                                {
                                    ((ServerSizeSummaryRow)sizeSummary.Select(filter)[0]).DateCreated = reader.GetDateTime(1);
                                }
                            }
                        }
                    }
                    catch { }
                }
            }
            finally
            {
                if (cmd.Connection.State == ConnectionState.Open)
                {
                    cmd.Connection.Close();
                }
            }
        }
Exemple #4
0
        public static ServerSizeSummary GetServerDatabaseInfo(ConnectionData connData)
        {
            Regex             nums = new Regex(@"\d{1,9}");
            ServerSizeSummary data = new ServerSizeSummary();
            string            location;
            Int64             dbSize;

            connData.DatabaseName = "master";
            DatabaseList  dbList        = GetDatabaseList(connData);
            SqlConnection conn          = SqlSync.Connection.ConnectionHelper.GetConnection(connData);
            string        locationQuery = "select filename from {0}.dbo.sysfiles where filename like '%.mdf'";
            string        sizeQuery     = "{0}.dbo.sp_spaceused";

            SqlCommand cmdLoc = new SqlCommand();

            cmdLoc.Connection = conn;
            SqlCommand cmdSize = new SqlCommand();

            cmdSize.Connection = conn;

            string dbName = string.Empty;

            for (int i = 0; i < dbList.Count; i++)
            {
                try
                {
                    conn.Open();

                    if (!dbList[i].IsManuallyEntered)
                    {
                        dbName = dbList[i].DatabaseName;
                        if (conn.State == ConnectionState.Closed)
                        {
                            conn.Open();
                        }


                        cmdLoc.CommandText  = String.Format(locationQuery, dbName);
                        cmdSize.CommandText = string.Format(sizeQuery, dbName);
                        location            = (string)cmdLoc.ExecuteScalar();
                        using (SqlDataReader reader = cmdSize.ExecuteReader())
                        {
                            reader.Read();
                            dbSize = Int64.Parse(nums.Match(reader[1].ToString()).ToString());
                        }
                        data.AddServerSizeSummaryRow(dbName, location, dbSize, DateTime.MinValue);
                    }
                }
                catch
                {
                    data.AddServerSizeSummaryRow(dbName, string.Empty, 0, DateTime.MinValue);
                }
                finally
                {
                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
            }

            data.AcceptChanges();
            AddDatabaseCreateDate(ref data, connData);
            data.AcceptChanges();
            return(data);
        }