snippetsqlModerate
How to drop SQL Server database currently in use and in Single user mode
Viewed 0 times
sqlusermodeanddatabasedropsinglehowserveruse
Problem
I have a Database on SQL Server 2008, which I want to drop.
Currently it is in single user mode and it is currently in use.
returns
and I do not know how to identify the session I have to kill.
An attempt to set it offline
yields
Currently it is in single user mode and it is currently in use.
select * from sys.sysprocessesreturns
Msg 924, Level 14, State 1, Line 1
Database 'G_MAIN_DE' is already open and can only have one user at a time.and I do not know how to identify the session I have to kill.
An attempt to set it offline
ALTER DATABASE G_MAIN_DE SET OFFLINE WITH ROLLBACK IMMEDIATEyields
Msg 5064, Level 16, State 1, Line 1
Changes to the state or options of database 'G_MAIN_DE' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.Solution
This built-in stored procedure shows all connections to a database
And this query kills a connection to the database, for example connection SPID #53
exec sp_who2And this query kills a connection to the database, for example connection SPID #53
exec kill 53Code Snippets
exec sp_who2exec kill 53Context
StackExchange Database Administrators Q#49385, answer score: 10
Revisions (0)
No revisions yet.