PDA

Click to See Complete Forum and Search --> : [RESOLVED] SQL Server Express Backup


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

ekim12987
Apr 17th, 2007, 10:50 AM
Any ideas from anyone, I would really like to be able to do this.

Thanks

jmcilhinney
Apr 17th, 2007, 06:00 PM
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.

mendhak
Apr 18th, 2007, 06:22 AM
Step through your code and look at what saveBackupDialog.FileName has as its value.

shakti5385
Apr 18th, 2007, 07:05 AM
Look (http://www.vbforums.com/showpost.php?p=2826473&postcount=2)

ekim12987
Apr 18th, 2007, 03:10 PM
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

Hack
Apr 24th, 2007, 06:25 AM
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 (http://www.c-sharpcorner.com/UploadFile/dclark/InsOutsinCS11302005072332AM/InsOutsinCS.aspx)

ekim12987
Apr 26th, 2007, 08:05 AM
Thanks, I got that to work.