SQL Server:将数据库模式设置为 RESTRICTED_USER WITH ROLLBACK IMMEDIATE 并不总是删除所有连接
我需要使用 SMO 从 .NET 执行数据库恢复。在恢复之前,我将数据库设置为 RESTRICTED_USER WITH ROLLBACK IMMEDIATE 模式。这在测试/调试期间工作正常 - 所有用户都被删除。但是,当此代码在夜间作为自动化过程的一部分运行时,有时会出现以下异常:
Microsoft.SqlServer.Management.Common.ExecutionFailureException:执行 Transact-SQL 语句或批处理时发生异常。 ---> System.Data.SqlClient.SqlException:无法获得独占访问权限,因为数据库正在使用中。 RESTORE DATABASE 异常终止
这里发生了什么?谢谢!
I need to perform a restore of database from .NET using SMO.Prior to the restore I set the database into RESTRICTED_USER WITH ROLLBACK IMMEDIATE mode. This works fine during testing/debugging - all users are dropped. However, when this code is run as part of an automated process at night, sometimes I get the following exception:
Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Exclusive access could not be obtained because the database is in use. RESTORE DATABASE is terminating abnormally
What's happening here? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你能不做吗?
然后在备份后添加另一个 TSQL 步骤:
或者,要找出在夜间运行时可能发生的情况,请以某种方式捕获“
Which”的结果,该结果将显示当时谁已连接。
Can you not do;
Then add another TSQL step after the backup:
Alternatively, to find out what could be happening as this is running at night, somehow capture the results of
Which would show you who is connected at the time.