Antonios Dev

Antonios Dev

  • NA
  • 39
  • 18.9k

Backup of SQL Server in specified location

Apr 24 2011 7:26 AM
Hi

I'm using SQL Server 2008 R2 Express. In my application I support backup of database. This works perfect except from the fact that it always saves the file to computer that SQL Server is installed and not on the PC the application runs. I would like to save the backup file in a desired location;
e.g a USB Stick.
My code is as follows:

private void buttonLocation_Click(object sender, EventArgs e)
       
{
           
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1
.InitialDirectory = @"c:\";
            saveFileDialog1.Filter = "
Backup files (*.bak)|*.bak| All files (*.*)|*.*";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBoxLocation.Text = saveFileDialog1.FileName;
                backupDeviceItem = new BackupDeviceItem(textBoxLocation.Text, DeviceType.File);
            }
        }


        private void buttonStartBackup_Click(object sender, EventArgs e)
        {
            if (textBoxLocation.Text.Length != 0)
            {
                backUp = new Backup();
                backUp.Database = comboBoxDataBases.SelectedItem.ToString();
                backUp.Action = BackupActionType.Database;
                backUp.Devices.Add(backupDeviceItem);
                backUp.Initialize = true;              
                backUp.SqlBackup(server);
            }
        }

Is there anyone that can help me please

Thanks in advance

Answers (2)