المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Backing up database file using SMO error



C# Programming
08-28-2010, 01:00 PM
Hi. I'm having problem with the way I Backup my database. I'm trying to use the SMO now because the first time I tried to backup my database with File.Copy() is I always have errors with the .dbo file that I'm backing up. I always have the error that the file is currently used by another process even if I already closed the connection. Now I'm still having problem with SMO. I encountered a run-time error saying: "the backup failed for the server ROJAI-PC". I don't know how to resolve the problem since I'm new to SMO. Can anyone help me?

Here is the code I used:
private void createBackupToolStripMenuItem_Click(object sender, EventArgs e)
{
Server srver = new Server();
Backup bckup = new Backup();

bckup.Devices.AddDevice(@"C:\Documents and Settings\Jairo Hibaler\Desktop\Backup\MP\HotelReservationSystem\HotelReservationSystem\bin\Debug\hotelReservationBa ckup.bak", DeviceType.File);
bckup.Database = "HotelReservationDB";
bckup.Action = BackupActionType.Database;
bckup.Initialize = true;
bckup.PercentCompleteNotification = 10;
bckup.PercentComplete += new PercentCompleteEventHandler(bckup_PercentComplete);
bckup.SqlBackup(srver);
}

private void bckup_PercentComplete(object sender, PercentCompleteEventArgs e)
{
MessageBox.Show(e.Percent.ToString() + "% backed up");
}