473,385 Members | 1,356 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,385 software developers and data experts.

SQLDMO.Backup and ProgressBar - help needed

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: "an*******@discussions.microsoft.com"
<an*******@discussions.microsoft.com> 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: "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
1 2534
an*******@discussions.microsoft.com wrote:
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: "an*******@discussions.microsoft.com"
<an*******@discussions.microsoft.com> 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
Nov 16 '05 #2

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

Similar topics

3
by: silven | last post by:
Hi all I am trying to do a Bulk Copy from a "tab delmimited" text file to a table in my database. I have it almost working except when the file has too few columns for the table (table has 421...
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...
2
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: 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...
2
by: clilush | last post by:
I've been working with db2 8.2fp14 for over a year now and was wondering what is a "standard" way of doing a backup to provide 24/7 operations with disaster recovery capabilities? My thoughts were...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.