Skip to content
Microsoft SQL Server

SQL Server Error 18456

Login failed for user

Severity 14 Logins & Permissions
Applies to: All supported SQL Server versions (2016 to 2025), Azure SQL Managed Instance; Azure SQL Database uses the same number
Last technically reviewed 23 October 2026 on SQL Server 2025 (17.0.1145.4)
The full message
Login failed for user 'app_user'.
Other forms of this message
SQL Server Management Studio
Login failed for user 'app_user'. (Microsoft SQL Server, Error: 18456)
sqlcmd with ODBC Driver 18
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Login failed for user 'app_user'..
SQL Server error log (the entry that holds the real state)
Error: 18456, Severity: 14, State: 5.
Login failed for user 'app_user'. Reason: Could not find a login matching the name provided. [CLIENT: 10.0.0.15]
Error number
18456
Severity
14 (user-correctable error)
State
1 to the client; the real state (2, 5, 8, 38, 58 and others) is in the error log (see the state table below)
Product
Microsoft SQL Server Database Engine
Versions
All supported SQL Server versions (2016 to 2025), Azure SQL Managed Instance; Azure SQL Database uses the same number
Last reviewed
23 October 2026

What it means

Error 18456 means SQL Server refused to log you in. The message is deliberately vague; the SQL Server error log holds a state number and a reason that say exactly what went wrong.

SQL Server raises 18456 when a connection fails authentication. To avoid helping an attacker, the client only ever sees a generic message with state 1: it never says whether the login name, the password, the authentication mode or database access was the problem. The same failure is written to the SQL Server error log with the true state number and, on current versions, a plain-English reason.

Severity 14 means a security-related error that the user or an administrator can correct. Nothing is wrong with the server itself. Use the state table below to match the state in the error log to its cause, then apply the matching fix.

What the state number tells you
StateMeaning
2 or 5The login name is not valid: no login with that name exists on this instance (check the server name in the connection string too).
6A Windows login name (DOMAIN\user) was used with SQL Server authentication.
7The login is disabled and the password is also wrong.
8The password is incorrect.
11 or 12The login is valid but server access failed, for example a Windows user who only has access through the local Administrators group without an elevated token.
18The password must be changed before the login can be used.
38 or 46The login is valid but the database requested in the connection could not be found or opened.
58SQL Server is set to Windows Authentication only and the client tried SQL Server authentication (or the SIDs do not match).
102 to 111, 132 to 133Microsoft Entra ID (Azure AD) authentication failure.
126The database requested by the user does not exist.

Common causes

  • A wrong password, or a password that was changed for the login but not in the application connection string (state 8).
  • The login does not exist on the instance you are connecting to, often because the connection string points at a development server name in production (state 2 or 5).
  • SQL Server authentication used against an instance configured for Windows Authentication only (state 58).
  • The login is disabled, locked out after failed attempts, or its password has expired or must be changed (states 7 and 18).
  • The login is fine but the database named in the connection is missing, offline or has no user for this login (states 38, 46 and 126; see also error 4060).

Diagnose it

Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.

Read the real state and reason from the error log

Run this as a member of the securityadmin or sysadmin role. The first query returns the Error: 18456, Severity: 14, State: N lines; the second returns the matching reasons.

-- State lines for recent failed logins (current error log)
EXEC sp_readerrorlog 0, 1, N'Error: 18456';

-- The reasons, with the login name and client address
EXEC sp_readerrorlog 0, 1, N'Login failed';
What to look for

A pair of lines such as State: 5 followed by Reason: Could not find a login matching the name provided. Match the state to the table above.

Check the login: exists, disabled, locked, expired, default database

SELECT sp.name,
       sp.type_desc,
       sp.is_disabled,
       sp.default_database_name,
       LOGINPROPERTY(sp.name, 'IsLocked')     AS is_locked,
       LOGINPROPERTY(sp.name, 'IsExpired')    AS is_expired,
       LOGINPROPERTY(sp.name, 'IsMustChange') AS must_change
FROM sys.server_principals AS sp
WHERE sp.name = N'app_user';
What to look for

No row means the login does not exist on this instance (state 2 or 5). is_disabled = 1, is_locked = 1, is_expired = 1 or must_change = 1 each point to a specific fix below. The LOGINPROPERTY columns are NULL for Windows logins.

Check whether the instance accepts SQL Server authentication

SELECT SERVERPROPERTY('IsIntegratedSecurityOnly') AS windows_authentication_only;
What to look for

1 means Windows Authentication only, so every SQL login fails with state 58. 0 means mixed mode.

Check that the target database is online

SELECT name, state_desc, user_access_desc
FROM sys.databases
WHERE name = N'Sales';
What to look for

ONLINE and MULTI_USER is normal. No row, OFFLINE, RESTORING or SINGLE_USER explains states 38, 46 and 126.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Correct the server name, login name or password in the connection

Client or network side

For states 2, 5 and 8, start with the client. Confirm the connection string targets the right server and instance, the login name is spelled exactly, and the password is current. Configuration files and deployment pipelines that inject connection strings are the usual culprits after a password change.

Reset the password of a SQL login

Changes permissions

If the password is genuinely lost (state 8) or must be changed (state 18), an administrator with ALTER ANY LOGIN can set a new one. Update every application that uses the login at the same time.

ALTER LOGIN [app_user] WITH PASSWORD = N'Use-a-strong-unique-password-1';

Enable or unlock the login

Changes permissions

For state 7, or when is_locked or is_disabled is 1, enable the login and unlock it. Unlocking a SQL login requires setting a password in the same statement. Find out why it was locked first: repeated failures may be an attack or a service with an old password.

ALTER LOGIN [app_user] ENABLE;
ALTER LOGIN [app_user] WITH PASSWORD = N'Use-a-strong-unique-password-1' UNLOCK;

Allow SQL Server authentication, or switch the application to Windows authentication

Changes configuration

For state 58 the instance only accepts Windows logins. The safer fix is often to connect with Windows authentication (for example Trusted_Connection=yes). If SQL logins are genuinely needed, an administrator can change the mode in SQL Server Management Studio: server Properties, Security, SQL Server and Windows Authentication mode, then restart the SQL Server service.

Caution: Changing the authentication mode needs a service restart. When the mode changes from Windows-only, the sa login is disabled; leave it disabled and use named logins instead.

Give the login access to the database it asks for

Changes permissions

For states 38, 46 and 126, either point the connection at a database the login can use, or create a user for the login in the target database and grant only the roles it needs.

-- Run in the target database (for example Sales)
CREATE USER [app_user] FOR LOGIN [app_user];
ALTER ROLE db_datareader ADD MEMBER [app_user];

Examples

A login that does not exist (state 5)

Connecting with sqlcmd as a login name that is not on the instance. The client shows the generic message; the error log shows state 5 and the reason.

-- From a command prompt:
-- sqlcmd -S . -C -U no_such_login -P "WrongPass#1" -Q "SELECT 1"

-- Then, as an administrator, read the error log:
EXEC sp_readerrorlog 0, 1, N'no_such_login';
Result
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Login failed for user 'no_such_login'..

Error log:
Error: 18456, Severity: 14, State: 5.
Login failed for user 'no_such_login'. Reason: Could not find a login matching the name provided. [CLIENT: <local machine>]

SQL authentication against a Windows-only instance (state 58)

Shown as documented by Microsoft (MSSQLSERVER_18456, state 58); not reproduced here, because the lab instance accepts SQL authentication and switching it to Windows-only mode needs a service restart.

-- The instance reports Windows Authentication only:
SELECT SERVERPROPERTY('IsIntegratedSecurityOnly');  -- returns 1

-- Any SQL login then fails, and the error log records:
Result
Error: 18456, Severity: 14, State: 58.
Login failed for user 'app_user'. Reason: An attempt to login using SQL authentication failed. Server is configured for Windows authentication only. [CLIENT: 10.0.0.15]

How to prevent it

Give each application its own login with only the database roles it needs, keep its password in a secrets store rather than in code, and rotate it with a plan that updates every consumer at once. Decide early whether the instance uses Windows authentication only or mixed mode, so deployments do not discover state 58 in production.

Alert on bursts of 18456 in the error log: a sudden run of state 8 or state 5 failures usually means a stale password after a change or someone guessing passwords. For broader hardening, see the SQL Server security lesson and how to avoid SQL injection.

Common questions

How do I find the real reason behind error 18456?

Read the SQL Server error log. The client always sees state 1, but the log records the true state and, on current versions, a Reason line. State 5 means the login does not exist, 8 a wrong password, 38 a database that cannot be opened and 58 SQL authentication against a Windows-only instance.

Why does sa fail with 18456 when the password is correct?

Either the instance accepts only Windows authentication (state 58), or the sa login is disabled (state 7). When an instance is switched from Windows-only to mixed mode, sa starts out disabled. Use a named login rather than enabling sa.

Is error 18456 a sign of an attack?

Sometimes. Occasional failures are usually typos or stale passwords, but many failures in a short time, especially for sa or for names that do not exist (state 5), can be password guessing. Check the client addresses in the error log.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 23 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.

Still stuck on a SQL Server error?

Browse the full SQL Server error library, or get hands-on help from an experienced SQL professional.