Error 18456
SQL Server error 18456: Login failed for user
Error 18456 is deliberately vague on the client. The state number in the SQL Server error log tells you the real cause — here is how to read it and fix each one.
- Applies to
- SQL Server 2016–2022, Azure SQL Managed Instance
- Updated
- Read time
- 1 min
What the error means
The client sees only:
Login failed for user 'app_user'. (Microsoft SQL Server, Error: 18456)
SQL Server hides the reason from the client on purpose. The detail lives in the error log, as a state number.
Find the state
EXEC xp_readerrorlog 0, 1, N'18456';
Look for a line like Error: 18456, Severity: 14, State: 8.
States and fixes
| State | Meaning | Fix |
|---|---|---|
| 2, 5 | Login does not exist | Create the login or check spelling |
| 6 | Windows login used with SQL auth | Use Integrated Security |
| 7 | Login disabled | ALTER LOGIN [name] ENABLE; |
| 8 | Wrong password | Reset the password |
| 11, 12 | Valid login, no server access | Grant CONNECT SQL; check UAC elevation |
| 18 | Password must be changed | Change password or turn off CHECK_EXPIRATION |
| 38 | Default database unavailable | Fix the default database |
| 58 | SQL auth disabled on server | Enable mixed mode and restart |
Enable mixed-mode authentication (state 58)
EXEC xp_instance_regwrite
N'HKEY_LOCAL_MACHINE',
N'Software\Microsoft\MSSQLServer\MSSQLServer',
N'LoginMode', REG_DWORD, 2;
Then restart the SQL Server service.
Fix the default database (state 38)
ALTER LOGIN [app_user] WITH DEFAULT_DATABASE = [master];
Verify
Reconnect with sqlcmd -S server -U app_user -P '***' -Q "SELECT SUSER_NAME();". A row back means you're done.