如何一次关闭所有活动的数据库连接?
How to close all active database connections in one shot?
在尝试恢复 SQL 服务器数据库或执行任何其他需要独占数据库访问的操作时,它显示以下错误:
Exclusive access could not be obtained because the database is in use.
这将完成您的要求,但会终止所有打开的连接并回滚未提交的更改
ALTER DATABASE <yourDB>
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
试试这个..
USE master
GO
ALTER DATABASE AdventureWorksDW
SET SINGLE_USER
--This rolls back all uncommitted transactions in the db.
WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE AdventureWorksDW
FROM ...
...
GO
要做的一件事是将数据库置于单用户模式。
来自MSDN
In Object Explorer, connect to an instance of the SQL Server Database
Engine, and then expand that instance. Right-click the database to
change, and then click Properties. In the Database Properties dialog
box, click the Options page. From the Restrict Access option, select
Single. If other users are connected to the database, an Open
Connections message will appear. To change the property and close all
other connections, click Yes
.
您可以 kill all processes that have open connections to a SQL Server database or alter database to single user mode 使用 no_wait 选项
ALTER DATABASE [Works] SET SINGLE_USER WITH NO_WAIT
在尝试恢复 SQL 服务器数据库或执行任何其他需要独占数据库访问的操作时,它显示以下错误:
Exclusive access could not be obtained because the database is in use.
这将完成您的要求,但会终止所有打开的连接并回滚未提交的更改
ALTER DATABASE <yourDB>
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
试试这个..
USE master
GO
ALTER DATABASE AdventureWorksDW
SET SINGLE_USER
--This rolls back all uncommitted transactions in the db.
WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE AdventureWorksDW
FROM ...
...
GO
要做的一件事是将数据库置于单用户模式。
来自MSDN
In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance. Right-click the database to change, and then click Properties. In the Database Properties dialog box, click the Options page. From the Restrict Access option, select Single. If other users are connected to the database, an Open Connections message will appear. To change the property and close all other connections, click Yes
.
您可以 kill all processes that have open connections to a SQL Server database or alter database to single user mode 使用 no_wait 选项
ALTER DATABASE [Works] SET SINGLE_USER WITH NO_WAIT