当我使用给定代码从该文件进行备份和恢复时,它会成功恢复,但是当我删除任何表的某些行并从同一个备份文件恢复我的数据库时,它会出错
“对象引用未设置为对象的实例”
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
cmd2 = new SqlCommand("USE MASTER RESTORE DATABASE plproject FROM DISK = '" + openFileDialog1.FileName + "' WITH REPLACE", Con);
dr = cmd1.ExecuteReader();
//cmd2.ExecuteNonQuery();
dr.Dispose();
MessageBox.Show("Database Restored", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
答案 0 :(得分:0)
编写存储过程或SqlCommand,如下所示。请检查此MSDN link
USE master
GO
RESTORE DATABASE AdventureWorks2012
FROM TAPE = '\\.\Tape0'
GO
答案 1 :(得分:0)
这个鳕鱼对我工作。 通过ado.net发送查询 (“使用主RESTORE DATABASE new_2SQL FROM DISK = N'D:\ backup.bak'WITH FILE = 1,NOUNLOAD,REPLACE,STATS = 10”);