October 10, 2011 at 2:27 am
Hi,
When I run this code, the event PercentCompleteEventHandler (Backup_PercentComplete); never fired.
Then event ServerMessageEventHandler(Backup_Complete) is fired
when the backup is complete.
The backup operation run Ok and without errors.
Runnig with vs 2008 and sql server 2008 r2 RTM
Objects SMO version 10.0.0.0
Any ideas?
The code:
using System;
using System.Data;
using System.Collections;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
class Program
{
static void Main(string[] args)
{
BackupDeviceItem bdi = new BackupDeviceItem(@"c:\temp\MyDB.bak", DeviceType.File);
Backup bu = new Backup( );
bu.Database ="MyDB";
bu.Devices.Add(bdi);
bu.Initialize =true;
bu.PercentCompleteNotification = 10;
// add percent complete and complete event handlers
bu.PercentComplete += new PercentCompleteEventHandler(Backup_PercentComplete);
bu.Complete += new ServerMessageEventHandler(Backup_Complete);
Server server = new Server("localhost");
bu.SqlBackup(server);
Console.WriteLine(Environment.NewLine + "Press any key to continue.");
Console.ReadKey( );
}
protected static void Backup_PercentComplete( object sender, PercentCompleteEventArgs e)
{
Console.WriteLine(Environment.NewLine + e.Percent + "% processed.");
}
protected static void Backup_Complete(object sender, ServerMessageEventArgs e)
{
Console.WriteLine(Environment.NewLine + e.ToString( ));
}
}
December 11, 2023 at 3:51 pm
I can't do it. Can you?
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply