SQLDMO.Backup and ProgressBar - help needed

G

Guest

Hi all I am posting this to check if anyone could help
me. The problem still persists. I am beginner in C#.
Thanks.
Subject: SQLDMO.Backup and ProgressBar - help please
From: "(e-mail address removed)"
<[email protected]> Sent: 11/11/2004
5:52:10 AM




Hi all,
continued from yesterday's posting...
I still haven't found a solution to this issue. I put a
breakpoint in
private void SqlBackupPercentComplete(string message, int
Percent)
{
progressBar1.Value = Percent;
progressBar1.Update();
}
and verified that the event does fire 10 times (every 10%
of the process is complete.) Why doesn't the progress bar
update? All your help is appreciated. Thanks a lot to
everyone that replied already and gave ideas.


Subject: SQLDMO.Backup and ProgressBar
From: "(e-mail address removed)"
<[email protected]> Sent: 11/10/2004
1:29:42 PM




Hi all
My requirement is to "on button_click, backup a SQL
database using SQLDMO.Backup object and update the
progress in a ProgressBar. The problem is the progress
bar does not update at all until the very end of the
backup process, when the backup is almost going to be
over, the progress bar updates itself once on a stretch,
which is no use,it is not showing any progress.

SQLDMO documentation says, the SQLDMO.Backup object fires
PercentComplete event every 10% of the process. I
appreciate all your help in figuring this out. Thanks a
lot.

private void button1_Click(object sender,
System.EventArgs e)
{
string DatabaseName = "MySqlServerDB";
string BackupFileName = PathFileName.Text;
string Prefix = " button1_Click: ";

//check if the text box contains a valid backup
name and path
if(!PathFileName.Text.EndsWith(".bak"))
{
MessageBox.Show("Enter a valid Backup
path and file name. ");
goto ExitClick;
}

string BackupDir = Path.GetDirectoryName
(BackupFileName);
if(!Directory.Exists(BackupDir))
{
MessageBox.Show("Invalid Path
specified. ");
goto ExitClick;
}
if(!JobHelperObj.CheckDiskSpace(BackupDir))
{
MessageBox.Show("Insufficient disk space
in the drive. Backup will not continue. ");
goto ExitClick;
}

this.Cursor = Cursors.WaitCursor;
progressBar1.Visible = true;

try
{
//declare an instance of SQLDMO.Backup
SQLDMO.Backup DMOBackup = new
SQLDMO.BackupClass();
SQLDMO.SQLServer SqlServerObj = new
SQLDMO.SQLServerClass();
SqlServerObj.Name = ".";
SqlServerObj.LoginSecure = true;
SqlServerObj.Connect(".",null,null);

DMOBackup.Database = DatabaseName;
DMOBackup.Files = BackupFileName;

// Delete the datafile to allow the
application to create a brand new file.
// This will prevent attaching the new
backup data to the old data if there
// is any.
if(File.Exists(BackupFileName))
File.Delete(BackupFileName);

DMOBackup.PercentComplete += new

SQLDMO.BackupSink_PercentCompleteEventHandler
(this.SqlBackupPercentComplete);

DMOBackup.SQLBackup(SqlServerObj);
MessageBox.Show("Backup complete");

this.Cursor = Cursors.Default;
progressBar1.Visible = false;
progressBar1.Value = 0;

DMOBackup = null;
}
catch(Exception excep)
{
TraceMessage = " ERROR: " + Prefix +
excep.Message + ". " + e.GetType().ToString() + ". " +
" Exception occurred. ";
ErrorMessage = " ERROR: Unable to get the
BackupPath from DAHS table. ";
Log(TraceMessage);
Log(ErrorMessage, true);
MessageBox.Show(excep.Message + " Backup failed.
One of the possible causes could be Insufficient disk
space. ");
}
ExitClick:;
}

private void SqlBackupPercentComplete(string message, int
Percent)
{
progressBar1.Value = Percent;
progressBar1.Update();
}
...


..
 
T

The Last Gunslinger

Hi all I am posting this to check if anyone could help
me. The problem still persists. I am beginner in C#.
Thanks.
Subject: SQLDMO.Backup and ProgressBar - help please
From: "(e-mail address removed)"
<[email protected]> Sent: 11/11/2004
5:52:10 AM




Hi all,
continued from yesterday's posting...
I still haven't found a solution to this issue. I put a
breakpoint in
private void SqlBackupPercentComplete(string message, int
Percent)
{
progressBar1.Value = Percent;
progressBar1.Update();
}
and verified that the event does fire 10 times (every 10%
of the process is complete.) Why doesn't the progress bar
update? All your help is appreciated. Thanks a lot to
everyone that replied already and gave ideas.

It sounds like the form is not updating because your current thread is
busy with the backup.
You can try putting in an Application.Doevents which will process all
waiting messages in the queue (such as updating your form).
A better (IMHO) method would be to move the backup to a worker thread
and raise an event back to your main thread and update your progress bar
on the main thread but this is a bit more technical.
You should be able to find resources on the net or in MSDN about
threading or post back with more questions.

HTH
JB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top