473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SQLDMO.Backup and ProgressBar - help please

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: "an*******@discussions.microsoft.com"
<an*******@discussions.microsoft.com> 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();
}
..
Nov 16 '05 #1
2 5495
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]
- mv*@spam.guard.caspershouse.com

<an*******@discussions.microsoft.com> wrote in message
news:55****************************@phx.gbl...
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: "an*******@discussions.microsoft.com"
<an*******@discussions.microsoft.com> 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();
}
.

Nov 16 '05 #2
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 theUI thread, and you aren't marshalling it correctly. To check this, just getthe thread id of the thread that you make the initial call on, and compareit against the thread id of the thread that the event comes in on.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<an*******@discussions.microsoft.com> wrote in message
news:55****************************@phx.gbl...
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: "an*******@discussions.microsoft.com"
<an*******@discussions.microsoft.com> 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();
}
.

.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Verve | last post by:
Hi, how to create an SQL DMO object in .net and use it to enumerate the properties of Sql server. Can we use this object to list properties without logging in to the server?
0
by: Chandra | last post by:
Hi, I tried the following: >>> from win32com.client import DispatchWithEvents >>> class BackupEvent: .... def OnPercentComplete(self, sMessage, nPercent): .... print sMessage,...
1
by: Mohammed Abdel-Razzak | last post by:
Dear sirs I`ve used SQLDMO to make a backup to my database How can I use it to restore database? thanks Mohammed
1
by: C# beginner | last post by:
Hi all, I am using SQLDMO.Backup for backing up SQL server databases. I need to implement a progress bar to show the progress. I have some sample VB code that is like this: Dim WithEvents...
1
by: | last post by:
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...
0
by: | last post by:
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) {...
1
by: | last post by:
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: ...
3
by: Dean L. Howen | last post by:
I tries to search for SQL server using SQLDMO, but it alway return null although I have updated SQL to sp3 Please tell me more.
1
by: PJHORNSA | last post by:
Hi all, I want to create a backup of a database using SQLDMO in C#. But I keep on getting a exception. If anyone can help me by providing code for this, it would be appreciated. Thanks in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.