LOGIN LOCKED — sa SQL Server 2008 R2  /  Instance Recovery

Unlocking the sa Login Host: CLIENTPCNAME  ·  Instance: CLIENTPCNAME\MARKSERVER  ·  Windows Login: CLIENTPCNAME\WHOAMIUSERNAME

A step-by-step recovery path for error -2147203018, where the SQL Server login policy has locked sa out after too many failed attempts. Two methods are covered, chosen by whether your Windows account already holds sysadmin rights on the instance.

Applies to: SQL Server 2008 R2 Instance: MARKSERVER (named) Access level required: Local Administrator Estimated time: 5–10 min
Captured error
Error No. −2147203018
[Microsoft][ODBC SQL Server Driver][SQL Server] Login failed for user 'sa' because the account is currently locked out. The system administrator can unlock it.
01

Diagnose your path

The fix branches in two directions depending on one fact: does CLIENTPCNAME\WHOAMIUSERNAME already hold sysadmin rights on this SQL instance? Try Method 1 first — if it fails, you need Method 2.

Method 1

Windows login already has sysadmin

Connect directly with Windows Authentication and unlock sa in one command. Fastest path — try this first.

Method 2

No sysadmin login exists

Restart the instance in single-user mode, grant yourself sysadmin, then unlock sa normally.

i

Before starting: confirm the instance name is really MARKSERVER. Run sqlcmd -L from a command prompt, or check Services (services.msc) for a service literally named SQL Server (MARKSERVER). Swap the name into every command below if it differs.

02

Method 1 — Direct unlock

Use this if CLIENTPCNAME\WHOAMIUSERNAME is already a sysadmin on the instance.

1

Open an elevated command prompt

Right-click Command Prompt → Run as administrator.

2

Connect with Windows Authentication

The -E flag uses your current Windows credentials — no password prompt.

Command Prompt — Administrator
C:\> sqlcmd -S CLIENTPCNAME\MARKSERVER -E
3

Unlock and reset the sa login

A new password is required by ALTER LOGIN even if you plan to keep it similar — choose something strong.

sqlcmd — 1>
1> ALTER LOGIN sa WITH PASSWORD = '8446606378' UNLOCK, CHECK_POLICY = OFF;
2> GO
3> EXIT
!

If this step returns a login failure instead of a syntax result, WHOAMIUSERNAME does not have sysadmin rights. Stop here and move to Method 2.

03

Method 2 — Single-user mode recovery

Use this when no Windows account currently has sysadmin rights on the instance. You will briefly restart SQL Server in a restricted mode that allows exactly one connection with implicit sysadmin access, grant yourself the role, then return to normal operation.

1

Stop the SQL Server service

Run from an elevated command prompt.

Command Prompt — Administrator
C:\> net stop MSSQL$MARKSERVER
2

Start the instance in single-user mode

Adjust the binary path if your install folder differs. This runs in the foreground — do not close the window.

Command Prompt — Administrator (Window A)
C:\> "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MARKSERVER\MSSQL\Binn\sqlservr.exe" -m -sMARKSERVER
● WINDOW A — leave open and running for the remainder of this method
3

Open a second elevated command prompt

This is a separate window from step 2 — Window A must stay running.

Command Prompt — Administrator (Window B)
C:\> sqlcmd -S CLIENTPCNAME\MARKSERVER -E
4

Grant sysadmin to CLIENTPCNAME\WHOAMIUSERNAME

In single-user mode, the first connecting Windows login gets implicit sysadmin — this is what makes the grant possible.

sqlcmd — 1> (Window B)
-- If the login does not exist yet:
1> CREATE LOGIN [CLIENTPCNAME\WHOAMIUSERNAME] FROM WINDOWS;
2> GO
3> EXEC sp_addsrvrolemember 'CLIENTPCNAME\WHOAMIUSERNAME', 'sysadmin';
4> GO
5> EXIT

If the login already exists, skip the CREATE LOGIN line and run only the sp_addsrvrolemember line.

5

Stop the single-user instance

Switch back to Window A.

Window A — foreground process
Ctrl+C
Confirm terminate batch job? (Y/N): Y
6

Restart SQL Server normally

Command Prompt — Administrator
C:\> net start MSSQL$MARKSERVER
7

Unlock and reset sa

Same command as Method 1, now that WHOAMIUSERNAME has sysadmin.

Command Prompt — Administrator
C:\> sqlcmd -S CLIENTPCNAME\MARKSERVER -E
1> ALTER LOGIN sa WITH PASSWORD = '8446606378' UNLOCK, CHECK_POLICY = OFF;
2> GO
3> EXIT
04

Why this keeps happening

There's no separate "group policy for sa." SQL Server 2008 R2 ties the sa login to the local Windows account lockout policy whenever CHECK_POLICY is ON. Two fixes exist, at two different scopes.

ScopeWhat it changesRecommended
Per-login
CHECK_POLICY = OFF
Exempts only the sa login from the Windows lockout/complexity policy going forward. Use this
Server-wide
secpol.msc
Sets Account Lockout Threshold to 0 for the whole machine — every local Windows account stops locking out, not just SQL logins. Avoid unless required
05

Verify the fix