Wednesday, October 5, 2011

how to query sql server database size


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string strCount;
            SqlConnection Conn = new SqlConnection
               ("Data Source=W3INTECH-PC\\sqlexpress;Initial Catalog=aliintDatb;Integrated Security=True;");
            SqlCommand testCMD = new SqlCommand
               ("sp_spaceused", Conn);

            testCMD.CommandType = CommandType.StoredProcedure;

            Conn.Open();

            SqlDataReader reader = testCMD.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Console.WriteLine("Name: " + reader["database_name"]);
                    Console.WriteLine("Size: " + reader["database_size"]);
                }
            }

            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...