{"id":1110,"date":"2008-01-04T03:07:02","date_gmt":"2008-01-04T03:07:02","guid":{"rendered":"\/blogs\/paul\/post\/Katmai-bug-SSMS-doesnt-drop-database-locks-when-leaving-the-context-of-a-database.aspx"},"modified":"2013-01-02T00:27:39","modified_gmt":"2013-01-02T08:27:39","slug":"katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/","title":{"rendered":"Katmai bug: SSMS doesn&#8217;t drop database locks when leaving the context of a database"},"content":{"rendered":"<p><FONT face=Verdana><FONT size=2><br \/>\n<P>I came across an interesting bug in Management Studio in the latest Katmai CTP today &#8211; when a connection disconnects from a database, SSMS doesn&#8217;t release the shared database lock that it holds. This prevents any operations that need exclusive database access (like a <FONT face=\"Courier New\">RESTORE<\/FONT>)&nbsp;and can be somewhat disconcerting if you don&#8217;t realize what&#8217;s going on. Try executing the following in SSMS in the November CTP:<\/P><FONT color=#0000ff size=2><br \/>\n<BLOCKQUOTE dir=ltr style=\"MARGIN-RIGHT: 0px\"><br \/>\n<P><FONT face=\"Courier New\">USE<\/FONT><\/FONT><FONT face=\"Courier New\"><FONT color=#000000 size=2> <\/FONT><FONT color=#0000ff size=2>master<\/FONT><FONT color=#808080 size=2>;<BR><\/FONT><\/FONT><FONT face=\"Courier New\" size=2>GO<\/P><\/FONT><FONT color=#0000ff size=2><br \/>\n<P><FONT face=\"Courier New\">CREATE<\/FONT><\/FONT><FONT face=\"Courier New\"><FONT color=#000000 size=2> <\/FONT><FONT color=#0000ff size=2>DATABASE<\/FONT><FONT color=#000000 size=2> MySSMSTest<\/FONT><FONT color=#808080 size=2>;<BR><\/FONT><\/FONT><FONT face=\"Courier New\" size=2>GO<\/P><\/FONT><FONT color=#0000ff size=2><br \/>\n<P><FONT face=\"Courier New\">USE<\/FONT><\/FONT><FONT face=\"Courier New\"><FONT color=#000000 size=2> MySSMSTest<\/FONT><FONT color=#808080 size=2>;<BR><\/FONT><\/FONT><FONT face=\"Courier New\" size=2>GO<\/P><\/FONT><FONT color=#0000ff size=2><br \/>\n<P><FONT face=\"Courier New\">CREATE<\/FONT><\/FONT><FONT face=\"Courier New\"><FONT color=#000000 size=2> <\/FONT><FONT color=#0000ff size=2>TABLE<\/FONT><FONT color=#000000 size=2> test <\/FONT><FONT color=#808080 size=2>(<\/FONT><FONT color=#000000 size=2>c1 <\/FONT><FONT color=#0000ff size=2>INT<\/FONT><FONT color=#808080 size=2>);<BR><\/FONT><\/FONT><FONT face=\"Courier New\" size=2>GO<\/P><\/FONT><FONT color=#0000ff size=2><br \/>\n<P><FONT face=\"Courier New\">USE<\/FONT><\/FONT><FONT face=\"Courier New\"><FONT color=#000000 size=2> <\/FONT><FONT color=#0000ff size=2>master<\/FONT><FONT color=#808080 size=2>;<BR><\/FONT><\/FONT><FONT face=\"Courier New\" size=2>GO<\/P><\/FONT><FONT color=#0000ff size=2><br \/>\n<P><FONT face=\"Courier New\">DROP<\/FONT><\/FONT><FONT face=\"Courier New\"><FONT color=#000000 size=2> <\/FONT><FONT color=#0000ff size=2>DATABASE<\/FONT><FONT color=#000000 size=2> MySSMSTest<\/FONT><FONT color=#808080 size=2>;<BR><\/FONT><\/FONT><FONT size=2><FONT face=\"Courier New\">GO<\/FONT><\/P><\/BLOCKQUOTE><\/FONT><br \/>\n<P>And you&#8217;ll see:<\/P><br \/>\n<BLOCKQUOTE dir=ltr style=\"MARGIN-RIGHT: 0px\"><br \/>\n<P><FONT face=\"Courier New\" color=#ff0000>Msg 3702, Level 16, State 4, Line 1<BR>Cannot drop database &#8220;MySSMSTest&#8221; because it is currently in use.<\/FONT><\/P><\/BLOCKQUOTE><br \/>\n<P>It works perfectly in SQLCMD in the same CTP, and also in SQL Server 2005. You can work around this by doing something like:<\/P><FONT color=#0000ff size=2><br \/>\n<BLOCKQUOTE dir=ltr style=\"MARGIN-RIGHT: 0px\"><br \/>\n<P><FONT face=\"Courier New\">ALTER<\/FONT><\/FONT><FONT face=\"Courier New\"><FONT color=#000000 size=2> <\/FONT><FONT color=#0000ff size=2>DATABASE<\/FONT><FONT color=#000000 size=2> MySSMSTest <\/FONT><FONT color=#0000ff size=2>SET<\/FONT><FONT color=#000000 size=2> <\/FONT><FONT color=#0000ff size=2>RESTRICTED_USER<\/FONT><FONT color=#000000 size=2> <\/FONT><FONT color=#0000ff size=2>WITH<\/FONT><FONT color=#000000 size=2> <\/FONT><FONT color=#0000ff size=2>ROLLBACK<\/FONT><FONT color=#000000 size=2> IMMEDIATE<\/FONT><FONT color=#808080 size=2>;<\/P><\/FONT><\/FONT><FONT size=2><br \/>\n<P><FONT face=\"Courier New\">GO<\/FONT><\/P><\/BLOCKQUOTE><\/FONT><br \/>\n<P>Not exactly ideal &#8211; but, hey, it&#8217;s only a CTP. This has already been reported in <a href=\"http:\/\/connect.microsoft.com\">Connect<\/a>&nbsp;as issue <a href=\"https:\/\/connect.microsoft.com\/SQLServer\/feedback\/details\/320135\/closed-connections-in-ssms-are-not-closed\">320135<\/a>&nbsp;&#8211; I added a workaround.<\/P><br \/>\n<P>I&#8217;ll post any further bugs that I find here as well as making sure they&#8217;re on Connect.<\/P><\/FONT><\/FONT><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I came across an interesting bug in Management Studio in the latest Katmai CTP today &#8211; when a connection disconnects from a database, SSMS doesn&#8217;t release the shared database lock that it holds. This prevents any operations that need exclusive database access (like a RESTORE)&nbsp;and can be somewhat disconcerting if you don&#8217;t realize what&#8217;s going [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,86,95],"tags":[],"class_list":["post-1110","post","type-post","status-publish","format-standard","hentry","category-example-scripts","category-sql-server-2008","category-tools"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Katmai bug: SSMS doesn&#039;t drop database locks when leaving the context of a database - Paul S. Randal<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Katmai bug: SSMS doesn&#039;t drop database locks when leaving the context of a database - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"I came across an interesting bug in Management Studio in the latest Katmai CTP today &#8211; when a connection disconnects from a database, SSMS doesn&#8217;t release the shared database lock that it holds. This prevents any operations that need exclusive database access (like a RESTORE)&nbsp;and can be somewhat disconcerting if you don&#8217;t realize what&#8217;s going [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2008-01-04T03:07:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-01-02T08:27:39+00:00\" \/>\n<meta name=\"author\" content=\"Paul Randal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Randal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/\",\"name\":\"Katmai bug: SSMS doesn't drop database locks when leaving the context of a database - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2008-01-04T03:07:02+00:00\",\"dateModified\":\"2013-01-02T08:27:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Katmai bug: SSMS doesn&#8217;t drop database locks when leaving the context of a database\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\",\"name\":\"Paul S. Randal\",\"description\":\"In Recovery...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\",\"name\":\"Paul Randal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"caption\":\"Paul Randal\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/paul\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Katmai bug: SSMS doesn't drop database locks when leaving the context of a database - Paul S. Randal","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/","og_locale":"en_US","og_type":"article","og_title":"Katmai bug: SSMS doesn't drop database locks when leaving the context of a database - Paul S. Randal","og_description":"I came across an interesting bug in Management Studio in the latest Katmai CTP today &#8211; when a connection disconnects from a database, SSMS doesn&#8217;t release the shared database lock that it holds. This prevents any operations that need exclusive database access (like a RESTORE)&nbsp;and can be somewhat disconcerting if you don&#8217;t realize what&#8217;s going [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/","og_site_name":"Paul S. Randal","article_published_time":"2008-01-04T03:07:02+00:00","article_modified_time":"2013-01-02T08:27:39+00:00","author":"Paul Randal","twitter_misc":{"Written by":"Paul Randal","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/","name":"Katmai bug: SSMS doesn't drop database locks when leaving the context of a database - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2008-01-04T03:07:02+00:00","dateModified":"2013-01-02T08:27:39+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/katmai-bug-ssms-doesnt-drop-database-locks-when-leaving-the-context-of-a-database\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"Katmai bug: SSMS doesn&#8217;t drop database locks when leaving the context of a database"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/","name":"Paul S. Randal","description":"In Recovery...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce","name":"Paul Randal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","caption":"Paul Randal"},"sameAs":["http:\/\/3.209.169.194\/blogs\/paul"],"url":"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/1110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/comments?post=1110"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/1110\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=1110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=1110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=1110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}