Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
5.00/5 (1 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:-
C#
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
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?

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
 
Share this answer
 
Comments
Member 13723143 13-Mar-18 2:59am    
Yes Edo. There is a way to to do it. Its very interesting way of doing so. You have to use backgroundworker and asynch call to database.

Please see the link here ,
https://stackoverflow.com/questions/20028989/display-progress-of-execution-through-progress-bar

Thanks,
Rashid Kumar Parida

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900