From 0140b623565e48e8f92c0c7244971038945326d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B3=BD=E5=B3=B0?= <295180200@qq.com> Date: Wed, 15 Sep 2021 10:07:37 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Program.cs b/Program.cs index b628441..0badd29 100644 --- a/Program.cs +++ b/Program.cs @@ -189,11 +189,14 @@ static void restore() var databaseName = headInfo[0].DatabaseName; var dataName = fileInfo[0].LogicalName; var logName = fileInfo[1].LogicalName; + var stopConnect = $"ALTER DATABASE {databaseName} SET OFFLINE WITH ROLLBACK IMMEDIATE"; string restorSql = $@"RESTORE DATABASE {databaseName} from disk= N'{item}' WITH NOUNLOAD, {(replace ? "REPLACE," : "")} MOVE '{dataName}' TO '{Path.Combine(recoverDir, string.Concat(databaseName, ".mdf"))}', MOVE '{logName}' TO '{Path.Combine(recoverDir, string.Concat(databaseName, ".ldf"))}';"; + Console.WriteLine($"正在关闭数据{databaseName}的当前连接"); + context.SqlQuery(stopConnect); Console.WriteLine($"正在还原{databaseName}"); context.SqlQuery(restorSql); Console.WriteLine($"还原{databaseName}成功");