我想在我的Web应用程序中添加一个选项来恢复数据库。这是StoredProcedure
:
ALTER PROCEDURE [Restore] @path NVARCHAR(MAX)
AS
BEGIN
EXEC('ALTER DATABASE Kimiakesht SET OFFLINE')
EXEC('ALTER DATABASE Kimiakesht SET SINGLE_USER WITH ROLLBACK IMMEDIATE')
RESTORE DATABASE Kimiakesht
FROM DISK = @path
WITH REPLACE
EXEC('ALTER DATABASE Kimiakesht SET MULTI_USER')
EXEC('ALTER DATABASE Kimiakesht SET ONLINE')
END
我在应用程序中调用此过程,如下所示:
string backupPath = "F:\restore\file.bak";
entity.Database.ExecuteSqlCommand(System.Data.Entity.TransactionalBehavior.DoNotEnsureTransaction, "EXEC [Restore] @path = N'" + backupPath + "'");
但我总是得到这个错误: