The following references need to be added

Microsoft.SqlServer.Smo
Microsoft.SqlServer.SmoEnum
Microsoft.SqlServer.ConnectionInfo



ServerConnection oCon = new ServerConnection(Server, DBUserID, DBPassword);

Server oServer = new Server(oCon);
Backup oBackUp = new Backup();

sFileName = BackupLocation + "\\" + DBName
+ "_" + System.DateTime.Now.ToString("dd_MM_yyyy hh_mm") + ".bak";

BackupDeviceItem oBackupDevice =
new BackupDeviceItem(sFileName, DeviceType.File);

oBackUp.Devices.Add(oBackupDevice);

//oBackUp.Devices.AddDevice(@"C:\DBbackup.bak", DeviceType.File);
//oBackUp.Devices.AddDevice(sFileName, DeviceType.File);

oBackUp.Database = DBName;
oBackUp.Action = BackupActionType.Database;
oBackUp.NoRecovery = false;
oBackUp.Initialize = true;
oBackUp.PercentCompleteNotification = 10;

oBackUp.PercentComplete += new PercentCompleteEventHandler(bkp_percentComplete);
oBackUp.SqlBackup(oServer);

protected void bkp_percentComplete(object sender, PercentCompleteEventArgs e)
{
lblStatus.Text = e.Percent.ToString() + "% backed up";
}

Category : | Read More......