You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/database-engine/configure-windows/connect-to-sql-server-when-system-administrators-are-locked-out.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: "Connect to SQL Server when system administrators are locked out"
3
3
description: Learn how to regain access to SQL Server as a system administrator if you've been mistakenly locked out.
4
4
author: rwestMSFT
5
5
ms.author: randolphwest
6
-
ms.date: 07/14/2022
6
+
ms.date: 08/21/2023
7
7
ms.service: sql
8
8
ms.subservice: configuration
9
9
ms.topic: conceptual
@@ -25,15 +25,15 @@ This article describes how you can regain access to the [!INCLUDE[ssDEnoversion]
25
25
26
26
- The logins that are members of the sysadmin fixed server role are for individuals who have left the company or who aren't available.
27
27
28
-
- The sa account is disabled or no one knows the password.
28
+
- The `sa` account is disabled or no one knows the password.
29
29
30
30
## Resolution
31
31
32
32
In order to resolve your access issue, we recommend that you start the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] in single-user mode. This mode prevents other connections from occurring while you try to regain access. From here, you can connect to your instance of SQL Server and add your login to the **sysadmin** server role. Detailed steps for this solution are provided in the [step-by-step-instructions](#step-by-step-instructions) section.
33
33
34
34
You can start an instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] in single-user mode with either the `-m` or `-f` options from the command line. Any member of the computer's local Administrators group can then connect to the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] as a member of the **sysadmin** fixed server role.
35
35
36
-
When you start the instance in single-user mode, first stop the [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Agent service. Otherwise, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Agent might connect first, taking the only available connection to the server and blocking you from logging in.
36
+
When you start the instance in single-user mode, stop the [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Agent service. Otherwise, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Agent might connect first, taking the only available connection to the server and blocking you from logging in.
37
37
38
38
It's also possible for an unknown client application to take the only available connection before you're able to sign in. In order to prevent this from happening, you can use the `-m` option followed by an application name to limit connections to a single connection from the specified application. For example, starting [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] with `-mSQLCMD` limits connections to a single connection that identifies itself as the **sqlcmd** client program. To connect through the Query Editor in [!INCLUDE[ssManStudio](../../includes/ssmanstudio-md.md)], use `-m"Microsoft SQL Server Management Studio - Query"`.
39
39
@@ -55,10 +55,10 @@ For step-by-step instructions about how to start [!INCLUDE[ssNoVersion](../../in
55
55
56
56
### Use PowerShell
57
57
58
-
#### Option 1: Run the steps directly in an executable notebook via Azure Data Studio
58
+
#### Option 1: Run the steps directly in an executable notebook using Azure Data Studio
59
59
60
60
> [!NOTE]
61
-
> Before attempting to open this notebook, check that Azure Data Studio is installed on your local machine. To install, go to[Learn how to install Azure Data Studio](../../azure-data-studio/download-azure-data-studio.md).
61
+
> Before attempting to open this notebook, check that Azure Data Studio is installed on your local machine. To install Azure Data Studio, see[Learn how to install Azure Data Studio](../../azure-data-studio/download-azure-data-studio.md).
62
62
63
63
> [!div class="nextstepaction"]
64
64
> [Open Notebook in Azure Data Studio](azuredatastudio://microsoft.notebook/open?url=https://raw.githubusercontent.com/microsoft/mssql-support/master/sample-scripts/DOCs-to-Notebooks/T-shooting-SQL-SystemAdmins-Locked-out.ipynb)
@@ -108,7 +108,7 @@ For step-by-step instructions about how to start [!INCLUDE[ssNoVersion](../../in
108
108
> `Sqlcmd: Error: Microsoft ODBC Driver X for SQL Server : Login failed for user 'CONTOSO\BobD'. Reason: Server is in single user mode. Only one administrator can connect at this time..`
109
109
110
110
1.**Mixed Mode (optional):** If your SQL Server is running in mixed authentication mode, you can also:
111
-
1. Grant the Sysadmin role membership to a SQL login. Execute code such as the following to create a new SQL Server authentication login that is a member of the sysadmin fixed server role. Replace "?j8:z$G=JE9" with a strong password of your choice.
111
+
1. Grant the **sysadmin** role membership to a SQL login. Execute code such as the following to create a new SQL Server authentication login that is a member of the **sysadmin** fixed server role. Replace `?j8:z$G=JE9` with a strong password of your choice.
112
112
113
113
If you have a default instance, use the name of the server.
114
114
@@ -117,7 +117,7 @@ For step-by-step instructions about how to start [!INCLUDE[ssNoVersion](../../in
117
117
sqlcmd.exe -E -S $sql_server_instance -Q "CREATE LOGIN TempLogin WITH PASSWORD = '$strong_password'; ALTER SERVER ROLE sysadmin ADD MEMBER TempLogin; "
118
118
```
119
119
120
-
1. Also, if your SQL Server is running in mixed authentication mode and you want to reset the password of an enabled **sa** account. Change the password of the sa account with the following syntax. Be sure to replace "j8:zG=J?E9" with a strong password of your choice:
120
+
1. Also, if your SQL Server is running in mixed authentication mode and you want to reset the password of an enabled **sa** account. Change the password of the sa account with the following syntax. Be sure to replace `j8:zG=J?E9` with a strong password of your choice:
121
121
122
122
If you have a default instance, use the name of the server.
123
123
@@ -151,17 +151,17 @@ Perform these instructions while logged in to Windows as a member of the local a
151
151
152
152
1. On the **Startup Parameters** tab, in the **Specify a startup parameter** box, type `-m` and then select **Add**. (That's a dash then lower case letter m.)
153
153
154
-
For some earlier versions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] there is no **Startup Parameters** tab. In that case, on the **Advanced** tab, double-click **Startup Parameters**. The parameters open up in a small window. Be careful not to change any of the existing parameters. At the very end, add a new parameter `;-m` and then select **OK**. (That's a semi-colon then a dash then lower case letter m.)
154
+
For some earlier versions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], there's no **Startup Parameters** tab. In that case, on the **Advanced** tab, double-click **Startup Parameters**. The parameters open up in a small window. Be careful not to change any of the existing parameters. At the very end, add a new parameter `;-m` and then select **OK**. (That's a semi-colon then a dash then lower case letter m.)
155
155
156
156
1. Select **OK**, and after the message to restart, right-click your server name, and then select **Restart**.
157
157
158
158
1. After [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] has restarted, your server will be in single-user mode. Make sure that [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Agent isn't running. If started, it will take your only connection.
159
159
160
-
1. From the Windows Start menu, right-click the icon for [!INCLUDE[ssManStudio](../../includes/ssmanstudio-md.md)] and select **Run as administrator**. This will pass your administrator credentials to SSMS.
160
+
1. From the Windows Start menu, right-click the icon for [!INCLUDE[ssManStudio](../../includes/ssmanstudio-md.md)] and select **Run as administrator**. This passes your administrator credentials to SSMS.
161
161
162
162
For earlier versions of Windows, the **Run as administrator** option appears as a submenu.
163
163
164
-
In some configurations, SSMS will attempt to make several connections. Multiple connections will fail because [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] is in single-user mode. Based on your scenario, perform one of the following actions.
164
+
In some configurations, SSMS attempts to make several connections. Multiple connections will fail because [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] is in single-user mode. Based on your scenario, perform one of the following actions.
165
165
166
166
1. Connect with Object Explorer using Windows Authentication, which includes your Administrator credentials. Expand **Security**, expand **Logins**, and double-click your own login. On the **Server Roles** page, select **sysadmin**, and then select **OK**.
167
167
@@ -199,7 +199,7 @@ Perform these instructions while logged in to Windows as a member of the local a
199
199
200
200
1. On the **Startup Parameters** tab, in the **Existing parameters**box, select`-m`and then select**Remove**.
201
201
202
-
For some earlier versions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] there is no **Startup Parameters** tab. In that case, on the **Advanced** tab, double-click **Startup Parameters**. The parameters open up in a small window. Remove the `;-m` that you added earlier, and then select**OK**.
202
+
For some earlier versions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], there's no **Startup Parameters** tab. In that case, on the **Advanced** tab, double-click **Startup Parameters**. The parameters open up in a small window. Remove the `;-m` that you added earlier, and then select **OK**.
203
203
204
204
1. Right-click your server name, and then select **Restart**. Make sure to start [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Agent again if you stopped it before starting [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] in single-user mode.
0 commit comments