[RESOLVED] SQL Server Express Backup
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:
HTML Code:
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
Re: SQL Server Express Backup
Any ideas from anyone, I would really like to be able to do this.
Thanks
Re: SQL Server Express Backup
What actually happens if you try to use a full path? If it won't let you do it then it probably isn't supported.
Re: SQL Server Express Backup
Step through your code and look at what saveBackupDialog.FileName has as its value.
Re: SQL Server Express Backup
Re: SQL Server Express Backup
Savefilebackup has "C:\Documents and Settings\Mike\My Documents\Backup.bak" which is the correct path to where i want to run it.
Is it possible to run a stored procedure in C#? I really dont understand them so I would like to do what I'm trying now.
thanks
Re: SQL Server Express Backup
Quote:
Originally Posted by ekim12987
Is it possible to run a stored procedure in C#? I really dont understand them so I would like to do what I'm trying now.
Have a look here
Re: SQL Server Express Backup
Thanks, I got that to work.