ekim12987
Apr 12th, 2007, 03:44 PM
I am trying to create a Win Form that can create a DB backup with the click of a button. I am trying to allow the user to set the directory to where the ".bak" will go.
Here is what I have:
if (saveBackupDialog.ShowDialog() == DialogResult.OK)
{
Backup bu = new Backup();
bu.Action = BackupActionType.Database;
bu.Database = "Test"; //database name
//BackupDeviceItem bdi = new BackupDeviceItem(saveBackupDialog.FileName, DeviceType.File);
BackupDeviceItem bdi = new BackupDeviceItem("Test.bak", DeviceType.File);
bu.Devices.Add(bdi);
try
{
Server server = new Server(); //server
bu.SqlBackup(server);
}
catch (Exception x)
{
MessageBox.Show(x.ToString());
Close();
}
}
If you look at the BackupDeviceItem, the commented outline is what I want to do. I want to store the backup to that location. But if I only use a filename it works (the uncommented line) and puts the file in "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup" .
Basically instead of putting the file in C:\\Program Files... I want it to go where teh user selects from the savedialog. Any help is appreciated.
Thanks
Here is what I have:
if (saveBackupDialog.ShowDialog() == DialogResult.OK)
{
Backup bu = new Backup();
bu.Action = BackupActionType.Database;
bu.Database = "Test"; //database name
//BackupDeviceItem bdi = new BackupDeviceItem(saveBackupDialog.FileName, DeviceType.File);
BackupDeviceItem bdi = new BackupDeviceItem("Test.bak", DeviceType.File);
bu.Devices.Add(bdi);
try
{
Server server = new Server(); //server
bu.SqlBackup(server);
}
catch (Exception x)
{
MessageBox.Show(x.ToString());
Close();
}
}
If you look at the BackupDeviceItem, the commented outline is what I want to do. I want to store the backup to that location. But if I only use a filename it works (the uncommented line) and puts the file in "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup" .
Basically instead of putting the file in C:\\Program Files... I want it to go where teh user selects from the savedialog. Any help is appreciated.
Thanks