{"id":23320,"date":"2023-03-15T16:47:30","date_gmt":"2023-03-15T15:47:30","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=23320"},"modified":"2023-09-14T09:21:55","modified_gmt":"2023-09-14T07:21:55","slug":"lost-access-to-sql-server-now-what","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/","title":{"rendered":"Lost access to SQL Server. Now what ?"},"content":{"rendered":"\n<p>In this blog we will explain what to do to regain the access to your SQL Server instance.  Here is our scenario : <br>&#8211; You have by accident removed all logins in SQL Server instance <br>&#8211; Your <strong>sa<\/strong> account by security and best practice is disabled <br>&#8211; So no possibility to login with a <strong>sqlcmd<\/strong> or your <strong>SSMS<\/strong> (SQL Server Management Studio) tools<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>First thing first, take a deep breath and be calm.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif\" alt=\"\" \/><\/figure>\n\n\n\n<p>Then here are the steps to regain your access to the SQL Server instance<\/p>\n\n\n\n<p>1- Connect to your server where the SQL Server instance is installed (do a RDP connection)<br><br>2- Make sure your are administrator on this server. This is really important <br><br>3- Stop the SQL Server instance by using the SQL Server Configuration Manager.<br><br>4- Run powershell as administrator <br><br>5- Navigate to the folder where the SQL Server executable is located. The default location is <code>\"C:\\Program Files\\Microsoft SQL Server\\MSSQL15.MSSQLSERVER\\MSSQL\\Binn\"<\/code> for SQL Server 2019<br><br>6- Type the following command and press Enter: (This command starts the SQL Server instance in single-user mode)<br><code>sqlservr.exe -m<\/code><br><br>7- Run another Powershell as administrator <br><br>8- Type the following command and press Enter: (This command will let you to connect to the instance)<br><code>sqlcmd -S localhost -E<\/code> <br><br>9- Now all you need to do is to create a login with the sysadmin role <br><code>CREATE LOGIN [LIFESAVER] WITH PASSWORD = 'Pa$$word123456'<br>GO<br>ALTER SERVER ROLE [sysadmin] ADD MEMBER [LIFESAVER]<br>GO<\/code><br><\/p>\n\n\n\n<p>Here we go, Now you can restart your instance and login with your login freshly created and then recreate your removed logins again. <br><br>enjoy \ud83d\ude00<br><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p> <br><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog we will explain what to do to regain the access to your SQL Server instance. Here is our scenario : &#8211; You have by accident removed all logins in SQL Server instance &#8211; Your sa account by security and best practice is disabled &#8211; So no possibility to login with a sqlcmd [&hellip;]<\/p>\n","protected":false},"author":26,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[198,99],"tags":[790,2873,2870,2872,51,2871,2082],"type_dbi":[2874],"class_list":["post-23320","post","type-post","status-publish","format-standard","hentry","category-database-management","category-sql-server","tag-disaster-recovery","tag-local-connection","tag-login","tag-lost-access-to-sql-server","tag-sql-server","tag-sqlcmd","tag-ssms","type-sql-server"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Lost access to SQL Server. Now what ? - dbi Blog<\/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.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Lost access to SQL Server. Now what ?\" \/>\n<meta property=\"og:description\" content=\"In this blog we will explain what to do to regain the access to your SQL Server instance. Here is our scenario : &#8211; You have by accident removed all logins in SQL Server instance &#8211; Your sa account by security and best practice is disabled &#8211; So no possibility to login with a sqlcmd [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-15T15:47:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-14T07:21:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif\" \/>\n<meta name=\"author\" content=\"Microsoft Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Microsoft Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/\"},\"author\":{\"name\":\"Microsoft Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4\"},\"headline\":\"Lost access to SQL Server. Now what ?\",\"datePublished\":\"2023-03-15T15:47:30+00:00\",\"dateModified\":\"2023-09-14T07:21:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/\"},\"wordCount\":242,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif\",\"keywords\":[\"disaster recovery\",\"local connection\",\"login\",\"lost access to sql server\",\"SQL Server\",\"sqlcmd\",\"SSMS\"],\"articleSection\":[\"Database management\",\"SQL Server\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/\",\"name\":\"Lost access to SQL Server. Now what ? - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif\",\"datePublished\":\"2023-03-15T15:47:30+00:00\",\"dateModified\":\"2023-09-14T07:21:55+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#primaryimage\",\"url\":\"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif\",\"contentUrl\":\"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Lost access to SQL Server. Now what ?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4\",\"name\":\"Microsoft Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g\",\"caption\":\"Microsoft Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/microsoft-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Lost access to SQL Server. Now what ? - dbi Blog","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.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/","og_locale":"en_US","og_type":"article","og_title":"Lost access to SQL Server. Now what ?","og_description":"In this blog we will explain what to do to regain the access to your SQL Server instance. Here is our scenario : &#8211; You have by accident removed all logins in SQL Server instance &#8211; Your sa account by security and best practice is disabled &#8211; So no possibility to login with a sqlcmd [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/","og_site_name":"dbi Blog","article_published_time":"2023-03-15T15:47:30+00:00","article_modified_time":"2023-09-14T07:21:55+00:00","og_image":[{"url":"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif","type":"","width":"","height":""}],"author":"Microsoft Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Microsoft Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/"},"author":{"name":"Microsoft Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4"},"headline":"Lost access to SQL Server. Now what ?","datePublished":"2023-03-15T15:47:30+00:00","dateModified":"2023-09-14T07:21:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/"},"wordCount":242,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#primaryimage"},"thumbnailUrl":"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif","keywords":["disaster recovery","local connection","login","lost access to sql server","SQL Server","sqlcmd","SSMS"],"articleSection":["Database management","SQL Server"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/","url":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/","name":"Lost access to SQL Server. Now what ? - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#primaryimage"},"thumbnailUrl":"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif","datePublished":"2023-03-15T15:47:30+00:00","dateModified":"2023-09-14T07:21:55+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#primaryimage","url":"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif","contentUrl":"https:\/\/media.giphy.com\/media\/3o6vXJZlfNfAYysryo\/giphy.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/lost-access-to-sql-server-now-what\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Lost access to SQL Server. Now what ?"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4","name":"Microsoft Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g","caption":"Microsoft Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/microsoft-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/23320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=23320"}],"version-history":[{"count":12,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/23320\/revisions"}],"predecessor-version":[{"id":23409,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/23320\/revisions\/23409"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=23320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=23320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=23320"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=23320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}