"Login failed for user" (Msg 18456)
The connection reached SQL Server fine — authentication is what failed. The state number in the error log, not the message text shown to the client, is what actually tells you why.
- SQL Server:
Msg 18456, Level 14, State 1, Server 'SQLSRV01', Line 1followed byLogin failed for user 'app_user'. - PostgreSQL:
FATAL: password authentication failed for user "app_user" - MySQL:
ERROR 1045 (28000): Access denied for user 'app_user'@'host' (using password: YES)
This is a different shape of error from most pages here — it's not about a query, it's about never getting far enough to run one. Nothing on this page runs in the playground below; see why at the bottom.
The error message you see is deliberately vague
State 1 is what the client always sees, on every version of SQL
Server, regardless of the real cause — Microsoft made this intentional
so a failed login attempt doesn't hand an attacker a free hint about
which part of the authentication was wrong (valid username, bad
password vs. no such username at all, for instance). The real reason
lives in the SQL Server error log on the server itself, as a
different state number:
| State | Meaning |
|---|---|
| 5 | Login (username) doesn't exist |
| 6 | User tried SQL auth but with a Windows-only login name |
| 7 | Login disabled, or SQL auth not allowed for it |
| 8 | Wrong password for a login that does exist |
| 11, 12 | Valid login, but Windows couldn't grant server access (permissions/policy) |
| 18 | Password has expired and must be changed |
If you only have what the application showed you — State 1 — you're
looking at a hint deliberately stripped of the real reason. Check the
server's own error log (in SSMS: Management → SQL Server Logs, or
xp_readerrorlog) for the matching 18456 entry with the real state
number.
The most common causes, by what actually produces them
Wrong password (State 8). The obvious one — confirm the credential the application is actually using isn't stale (a connection string pointing at an old password after a rotation is the usual culprit).
Server set to Windows Authentication only, but something tried SQL
auth (State 6). Check the server's authentication mode:
SELECT SERVERPROPERTY('IsIntegratedSecurityOnly'); — 1 means SQL
logins can't authenticate at all, regardless of password correctness.
The login exists but has no mapped database user, or the mapping is orphaned (common after restoring a database backup onto a different server — the login SID and the database user's SID no longer match). Fix with:
ALTER USER app_user WITH LOGIN = app_user;
-- or, to re-check for orphans first:
EXEC sp_change_users_login 'Report';The sa login specifically, right after switching to Mixed Mode
(State 7). Enabling SQL authentication doesn't automatically enable
the sa account — it starts disabled and needs its own
ALTER LOGIN sa ENABLE; plus a password set.
What this isn't
If the client can't reach the server at all — connection timeout, "server
not found," no TCP response — that's a different problem with a different
error entirely; see the network-related connection
error. 18456 specifically
means the connection succeeded and SQL Server rejected the credentials
it was handed.
Can't demonstrate this in the playground
Authentication is a server/connection concept — the SQLite sandbox here has no login system, no server to connect to, and nothing to authenticate against. Reproduce this by starting SQL Server in Mixed Mode and attempting a login with a wrong password, then compare the client-side message against the real state number in the server's own error log.
- A network-related or instance-specific error occurred — the "can't even reach the server" error this page is often confused with.
- SELECT permission was denied — the next wall after login succeeds: authenticated, but not authorized for this object.
- Transactions — once connected, what a session can actually do.