Beispiel #1
0
        public string SqlStatement()
        {
            string result = DatabaseNameSize.SqlStatement();

            return(result);
            // TODO: add assertions to method DatabaseNameSizeTest.SqlStatement()
        }
Beispiel #2
0
        /// <summary>
        /// Gets the size and name of the database.
        /// </summary>
        /// <param name="database">The database.</param>
        /// <returns>the size and name of the database</returns>
        public List <DatabaseNameSize> GetDatabaseNameSize(string database)
        {
            this.ExecuteUseDatabase("master");
            List <DatabaseNameSize> results = new List <DatabaseNameSize>();
            DatabaseNameSize        resultrow;
            string sqlString = DatabaseNameSize.SqlStatement();

            sqlString = string.Format("EXEC sp_executesql @statement = N'{0}'", sqlString.Replace("'", "''"));

            using (SqlConnection connection = new SqlConnection(this.ConnectionString))
                using (SqlCommand command = new SqlCommand(sqlString, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            resultrow = new DatabaseNameSize(
                                reader.GetString(reader.GetOrdinal("DatabaseName")),
                                reader.GetString(reader.GetOrdinal("LogicalName")),
                                reader.GetString(reader.GetOrdinal("PhysicalName")),
                                reader.GetInt32(reader.GetOrdinal("Size_MB")));

                            results.Add(resultrow);
                        }
                    }

                    connection.Close();
                }

            return(results);
        }