2
Answers

Backup of SQL Server in specified location

Ask a question
Antonios Dev

Antonios Dev

13y
2.1k
1
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)