Click here to Skip to main content
12,457,938 members (50,506 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: .NET3.5 C# .NET SQL-Server , +
Hello,

I am creating windows application for create sql server database backup.
It's have done successfully but i want to show progress bar during create database backup in local drive.

my code is:-
string dbName="abc";
SqlConnection con = new SqlConnection(cnString1);
string DestDir = @"C:\DatabaseBackup";
if (!System.IO.Directory.Exists(DestDir))
{
   System.IO.Directory.CreateDirectory(@"C:\DatabaseBackup");
}
try
{
   con.Open();
   SqlCommand cmd = new SqlCommand("BACKUP DATABASE " + dbName + " TO DISK='" + DestDir + "\\" + dbName + ".bak' WITH FORMAT", con);
   cmd.ExecuteNonQuery();
 
   con.Close();
   MessageBox.Show("Database Backup Created 'C:\\DatabaseBackup\' drive and folder ");
So,
How could that possible in this code?

Thank You.
Ankit Agarwal
Software Engineer
Posted 16-Jan-13 1:39am
Updated 16-Jan-13 4:05am
v2
Comments
Zoltán Zörgő 16-Jan-13 7:43am
   
You are using my answer: http://www.codeproject.com/Answers/525950/How-can-we-overwrite-of-existing-sql-server-data-b.aspx#answer1, but you have not accepted it :(
rastogi.siddharth 16-Jan-13 7:48am
   
Take help from this link, which is very nice article:-
http://www.codeproject.com/Articles/449594/Progress-Bars-Threads-Windows-Forms-and-You
Zoltán Zörgő 17-Jan-13 16:26pm
   
Any progress?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi Ankit,

Good question (5+)
However, the answer is simply - No.
Getting events of the backup process is, currently not possible.
so you can't really get a progress bar for this.

[idea] Perhaps you might go around and (if you can estimate the backedup DB size) perform checks on the file size, and then show the estimation percentage on the GUI.

Using Zoltán's MSDN link is good for getting an event at the end, which is some indication but not of the process itself.

* if you do find a miraculous way to perform such a thing, do let us know, will you?

Cheers,
Edo
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160826.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100