{"id":155,"date":"2012-04-18T11:12:58","date_gmt":"2012-04-18T11:12:58","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2012\/04\/18\/cannot-drop-database-because-it-is-currently-in-use\/"},"modified":"2012-04-18T11:12:58","modified_gmt":"2012-04-18T11:12:58","slug":"cannot-drop-database-because-it-is-currently-in-use","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2012\/04\/18\/cannot-drop-database-because-it-is-currently-in-use\/","title":{"rendered":"cannot drop database because it is currently in use"},"content":{"rendered":"

When you try to drop a database you get the below error:
\n
\nMsg 3702, Level 16, State 3, Line 1
\nCannot drop database \u201cDataBaseName\u201d because it is currently in use.
\n<\/font><\/p>\n

How to drop database when this error occurs?<\/strong>
\n1. Check if you are using the database you are trying to drop
\n– Close all the SQL Server management studio windows that are open
\n– Re-Connect to the server
\n– Try to drop the database.<\/p>\n

2. Check if you are using the same database connection and trying to drop it.
\n– Change the database in the connection and try to run the drop statement.<\/p>\n

\"\"<\/a>
Drop Database Using Same Database<\/figcaption><\/figure>\n

3. Check if the script is trying to use the database that is to be dropped.
\n[sql]
\nUSE TestShrink
\nDROP DATABASE TestShrink
\n[\/sql]<\/p>\n

Change this to:
\n[sql]
\nUSE master
\nDROP DATABASE TestShrink
\n[\/sql]<\/p>\n

4. Kill all the sessions that are using the database you are trying to drop
\n[sql]
\nEXEC sp_who2
\n–Run kill spid for each process that is using the database to be dropped.
\nkill <<processid>> — Kill 57
\n[\/sql]
\nKill the sessions and try to drop the database.<\/p>\n","protected":false},"excerpt":{"rendered":"

When you try to drop a database you get the below error: Msg 3702, Level 16, State 3, Line 1 Cannot drop database \u201cDataBaseName\u201d because it is currently in use. How to drop database when this error occurs? 1. Check if you are using the database you are trying to drop – Close all the…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128,3],"tags":[1571,1572,1573,1574,1575,1576,1577,1578,1579,1580,1581,1582,1583,1584,1585,1586,1587],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/155"}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=155"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/155\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}