-1

当我使用给定的代码从该文件进行备份和恢复时,它会成功恢复,但是当我删除任何表的某些行并从同一个备份文件恢复我的数据库时,它会给出错误

“你调用的对象是空的”

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);
}
4

2 回答 2

0

编写存储过程或 SqlCommand 如下。检查这个MSDN 链接

USE master
GO
RESTORE DATABASE AdventureWorks2012
   FROM TAPE = '\\.\Tape0'
GO
于 2013-07-18T05:22:08.900 回答
0

这条鳕鱼为我工作。通过 ado.net 发送查询(“使用主 RESTORE DATABASE new_2SQL FROM DISK = N'D:\backup.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10”);

于 2015-11-28T15:53:08.697 回答