如何使用实体框架在ASP.Net Web应用程序中恢复本地数据库?

时间:2014-06-27 16:53:37

标签: sql-server entity-framework restore mdf local-database

我想在我的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 + "'");

但我总是得到这个错误:

enter image description here

0 个答案:

没有答案