0
我知道這可能看起來是一個重複的問題,但以前的問題無法解決我的問題。
我用這段代碼恢復了我創建的備份。恢復數據庫備份的錯誤
public string conrestore = "Data Source=.;Integrated Security=True";
private void btn_restore_Click(object sender, EventArgs e)
{
SqlConnection.ClearAllPools();
using (SqlConnection con = new SqlConnection(conrestore))
{
ServerConnection srvconn = new ServerConnection(con);
Server srvr = new Server(srvconn);
if (srvr != null)
{
try
{
Restore restoredb = new Restore();
restoredb.Action = RestoreActionType.Database;
restoredb.Database = "3LStoreDB";
OpenFileDialog openfd = new OpenFileDialog();
openfd.Filter = "Backup File (*.Bak)|*.Bak";
Nullable<bool> result = Convert.ToBoolean(openfd.ShowDialog());
if (result == true)
{
BackupDeviceItem bkDevice = new BackupDeviceItem(openfd.FileName, DeviceType.File);
restoredb.Devices.Add(bkDevice);
restoredb.ReplaceDatabase = true;
restoredb.SqlRestore(srvr);
MessageBox.Show("Restored successfully.");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
它可以正常工作,直到行
restoredb.SqlRestore(srvr);
它顯示錯誤Restore failed for server 'Server Name'
我不知道有什麼不對的代碼,我會很感激的任何幫助。