Cannot drop database because it is currently in use
before dropping a database, you drop the connection to that database first.
I have found a solution at http://www.kodyaz.com/articles/kill-all-processes-of-a-database.aspx
DECLARE @DatabaseName nvarchar(50)SET @DatabaseName = N'YOUR_DABASE_NAME'DECLARE @SQL varchar(max)SELECT @SQL = COALESCE(@SQL,'') + 'Kill ' + Convert(varchar, SPId) + ';'FROM MASTER..SysProcessesWHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId--SELECT @SQL EXEC(@SQL)
Someone connected to the database. Try to switch to another database and then, to drop it:
Try
SP_WHO
to see who connected
and KILL
if needed
It's too late, but it may be useful for future users.
You can use the below query before dropping the database query:
use master go alter database [MyDatbase] set single_user with rollback immediate drop database [MyDatabase]
It will work. You can also refer to
How do I specify "close existing connections" in sql script
I hope it will help you :)