Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 2:39am
Edited 16-Jan-13 5:05am
v2
Comments
Zoltán Zörgő at 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 at 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ő at 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
0 OriginalGriff 350
1 Sergey Alexandrovich Kryukov 133
2 Sebastiaan Meijerink 105
3 Rana Waqas 100
4 Abhinav S 95
0 Sergey Alexandrovich Kryukov 6,558
1 OriginalGriff 6,268
2 Peter Leow 2,534
3 Abhinav S 2,344
4 Maciej Los 2,297


Advertise | Privacy | Mobile
Web02 | 2.8.150414.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2015
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