Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:08:50+00:00 2026-06-12T02:08:50+00:00

Basically I’m creating a replication application and I just need to figure out the

  • 0

Basically I’m creating a replication application and I just need to figure out the database size and how much free space I have available on the D:\ drive.

If the database size is larger than the free space, then I need to alert the user.

This is what I have so far:

First I find out how much free space there is in the D drive.

DriveInfo di = new DriveInfo(@"D:\");

if (di.IsReady)
{
    freeSpace = di.TotalFreeSpace;
}

Then I get the size of the database I’m going to replicate:

dbSize = Database.GetDatabaseSize(ddlPublisherServer.Text, ddlPublisherDatabase.Text);

Here’s the method that gets the size of the DB. I don’t know if there’s a better way to do this but the size comes with the “MB” string in it so I need to remove it.

public static long GetDatabaseSize(string server, string database)
{
     string finalConnString = Properties.Settings.Default.rawConnectionString.Replace("<<DATA_SOURCE>>", server).Replace("<<INITIAL_CATALOG>>", database);

      using (SqlConnection conn = new SqlConnection(finalConnString))
      {
          using (SqlCommand cmd = new SqlCommand("sp_spaceused", conn))
          {
              cmd.CommandType = CommandType.StoredProcedure;

              conn.Open();
              cmd.ExecuteNonQuery();

              using (SqlDataAdapter da = new SqlDataAdapter(cmd))
              {
                  using (DataSet ds = new DataSet())
                  {
                      da.Fill(ds);

                      var spaceAvailable = ds.Tables[0].Rows[0][1].ToString();

                      string freeSpace = spaceAvailable.Remove(spaceAvailable.Length - 3, 3);

                      return Convert.ToInt64(freeSpace);
                   }
              }
         }
     }
}

My question now is –

How do I go about converting bytes to mega bytes so I can compare the db size and the disk free space?

This is what I have but it’s mega bytes and bytes so I need to do a conversion here.

if (dbSize > freeSpace)
{
     ClientScript.RegisterStartupScript(this.GetType(), "Insufficient Space", "alert('The database size is greater than the available space on the drive. Please make some room for the database in D drive of the subscriber server.');", true);
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:08:51+00:00Added an answer on June 12, 2026 at 2:08 am

    Bytes to Megabytes = Bytes / (1024 * 1024)
    Megabytes to Bytes = Megabytes * (1024 * 1024.0)

    Be sure to account for integer division, thus the 1024.0 so a floating point number is used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have a web service connected to a database, that has an insert
Basically I have a fixed size IFRAME with overflow: auto . The IFRAME displays
Basically what I have to do, is write a Image to the database. As
Basically I am creating a dynamic google map that pulls information from the database,
Basically this is related to a squash application where we have 2 scores. One
Basically I need to get older version of a file in the repository without
Basically, I have a UIImageView that will loop through 8 PNGs over 0.5 seconds.
Basically I have a large set of data in excel, and I was wondering
Basically, I have a list of delivery checkboxes one for deliver to this address
Basically, what I have is a setInterval inside a function. What I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.