SQL Server · error reference
SQL Server Error 18456: Login failed for user
Login failed for user 'app'. (Microsoft SQL Server, Error: 18456)
Error 18456 covers a dozen different refusals. The client is always told State 1; the SQL Server error log records the real state, and the state is the diagnosis.
What the database is telling you
The login was refused. SQL Server hides the reason from the client — every 18456 reaches it as State 1 — and writes the true state to its error log, where each number maps to one cause: a wrong password, a login that does not exist, a default database it cannot open, or SQL logins not being enabled at all.
Why it shows up in a migration
Migrations usually connect with a SQL login rather than Windows authentication, from a machine outside the domain. That is exactly when a server configured for Windows-only authentication, or a login whose default database was dropped, refuses the connection.
Common causes
- State 8: the password is wrong.
- State 5: no login with this name exists.
- State 58: the server is in Windows authentication mode, so SQL logins are refused outright.
- State 38 or 40: the login's default database (or the one in the connection string) cannot be opened — dropped, offline, or no user mapped in it.
- State 18: the password must be changed before first use. State 7: the login is disabled.
How to fix it
- 1
Find the real state in the error log.
EXEC sp_readerrorlog 0, 1, N'18456';
- 2
State 58 — enable SQL Server and Windows authentication (Server properties → Security), then restart the service. To check the current mode:
SELECT SERVERPROPERTY('IsIntegratedSecurityOnly') AS windows_only; -- 1 = Windows only - 3
State 8 / 18 / 7 — reset the password, clear the must-change flag, enable the login.
ALTER LOGIN app WITH PASSWORD = 'new-password', CHECK_EXPIRATION = OFF; ALTER LOGIN app ENABLE;
- 4
State 38 / 40 — point the login at a database it can open, and map a user in the one you need.
ALTER LOGIN app WITH DEFAULT_DATABASE = master; USE shop; CREATE USER app FOR LOGIN app;
What DBShifts does about it
Connection diagnosis classes a refused SQL Server login as "Authentication failed" and points at the user, the password and the source address. It cannot see the state either — that is server-side by design — so the error log is the next stop, and the state list above is what to look for.
Connection diagnosis
Connecting a database?
Add the database to DBShifts and the connection is tested on the spot. If it fails, you get which of these errors it is and what to change — not the driver's raw message. Once it connects, browse it, migrate it, or let an AI agent read it through the gateway with sensitive columns masked.