My problem is that I can't restore my database in wpf using C# code. The error is 'Restore failed for Server 'DELL/LOCALSERVER'. I just found the code I'm using and it's this one:
//for getting .bak file path
private void btnBrowse_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
txtBackupPath.Text = ofd.FileName;
}
private void btnRestore_Click(object sender, RoutedEventArgs e)
{
ServerConnection con = new ServerConnection(@server, userId, password);
Server sqlServerInstance = new Server(con);
Restore destination = new Restore();
destination.Action = RestoreActionType.Database;
destination.Database = initial_catalog;
BackupDeviceItem source = new BackupDeviceItem(txtBackupPath.Text, DeviceType.File);
destination.Devices.Add(source);
destination.ReplaceDatabase = true;
destination.SqlRestore(sqlServerInstance);
System.Windows.Forms.MessageBox.Show("The restore of database " + "'H2RPDB'" + " completed sccessfully", "Microsoft SQL Server Management Studio", MessageBoxButtons.OK, MessageBoxIcon.Information);
con.Disconnect();
}
I don't know what's wrong being new to this code. Thanks for the answers.
C:\test.bakis on the servers C: disk.