本文介绍了如何通过C#代码还原SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试恢复这样的数据库:

  SQL = @RESTORE DATABASE MYDATABASE TO DISK ='D:\\ \\MyDATA.BAK'; 
CMD =新的SqlCommand(SQL,康涅狄格州);
Cmd.ExecuteNonQuery();
Cmd.Dispose();



但我总是得到错误:



解决方案

Your DB connection is most likely to the database you're trying to restore. So there is a DB shared lock which prevents the restore of your db

Try this

SQL = @"USE master BACKUP DATABASE MyDataBase TO DISK='d:\MyDATA.BAK'";

Or change the connection details to use master DB

这篇关于如何通过C#代码还原SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 23:30