SQLDMO.Backup and ProgressBar - help please

G

Guest

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();
}
..
 
N

Nicholas Paldino [.NET/C# MVP]

I would guess that the event is coming in on a different thread than the
UI thread, and you aren't marshalling it correctly. To check this, just get
the thread id of the thread that you make the initial call on, and compare
it against the thread id of the thread that the event comes in on.

Hope this helps.
 
G

Guest

Thanks Nicholas for your reply. I am only a beginner in
C#. I don't understand what you said very well.
Interestingly, every one out of 3 or 4 times I do this
backup process, the progress bar updates. The other
times, it doesn't update. Do you still think this might
be a thread issue? Thanks for all your help.
-----Original Message-----
I would guess that the event is coming in on a different thread than the
UI thread, and you aren't marshalling it correctly. To check this, just get
the thread id of the thread that you make the initial call on, and compare
it against the thread id of the thread that the event comes in on.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

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();
}
.


.
 

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