Quick Answer
SQL Server Error 18456 indicates an authentication failure during login attempts. The error occurs when SQL Server's authentication subsystem rejects connection attempts due to invalid credentials, disabled accounts, wrong authentication modes, or password policy violations. This is typically concerning as it may indicate brute force attacks, misconfigured applications, or service account issues.
Root Cause Analysis
Error 18456 originates in SQL Server's security subsystem during the login authentication phase, specifically in the SQL Server Database Engine's authentication manager. The error manifests in multiple stages of the authentication process, each generating different state codes that pinpoint the exact failure reason.
When a connection request reaches SQL Server, the authentication manager validates credentials through either SQL Server authentication or Windows authentication modes. For SQL authentication, the engine validates the username and password hash against sys.sql_logins. For Windows authentication, it validates through SSPI calls to the domain controller or local security authority.
The authentication process involves several critical checks: login existence validation, password verification, login status (enabled/disabled), password expiration policies, account lockout policies, and database access permissions. Each failure point generates the same 18456 error but with different state codes in the SQL Server error log.
State codes provide granular failure reasons. Common values include:
- State 1: Generic error; the true state is intentionally hidden from the client and only the real state appears in the SQL Server error log.
- State 2: Invalid user - the login does not exist.
- State 5: User not found (invalid user ID lookup).
- State 6: A Windows login was attempted using SQL Server authentication.
- State 7: Login exists but is disabled, or an incorrect password was supplied for a disabled login.
- State 8: Incorrect password.
- State 11: Valid login, but server access failed (often default database access issues).
- State 12: Valid login, but server access failed.
- State 13: Permission denied (e.g., server is paused).
- State 18: The login's password must be changed at next login.
- State 38: The database specified for the login cannot be opened.
- State 40: The default database for the login cannot be opened.
SQL Server 2016 introduced enhanced security logging that provides more detailed state information compared to earlier versions.
The authentication subsystem also enforces login triggers, which can cause 18456 errors even with valid credentials if the trigger logic fails. SQL Server 2019 and later versions improved the error logging granularity for certificate-based authentication failures and contained database user authentication issues.
AutoDBA checks authentication failure patterns, login security configurations, and password policy compliance across your entire SQL Server instance in 60 seconds. Download the free diagnostic script and see what else needs attention.
Diagnostic Queries
-- Check recent authentication failures from error log
EXEC xp_readerrorlog 0, 1, N'Login failed for user', N'18456'
This reveals recent login failures with state codes and timestamps to identify patterns or brute force attempts.
-- Examine login properties and status
SELECT
name,
type_desc,
is_disabled,
is_policy_checked,
is_expiration_checked,
create_date,
modify_date,
LOGINPROPERTY(name, 'DaysUntilExpiration') AS days_until_expiration,
LOGINPROPERTY(name, 'IsLocked') AS is_locked,
LOGINPROPERTY(name, 'IsExpired') AS is_expired,
LOGINPROPERTY(name, 'IsMustChange') AS is_must_change
FROM sys.sql_logins
WHERE name = 'problematic_login_name'
This shows login configuration issues like disabled status, password policies, or expiration settings.
-- Check database user mappings
SELECT
dp.name AS principal_name,
dp.type_desc AS principal_type,
o.name AS object_name,
p.permission_name,
p.permission_state_desc
FROM sys.database_permissions p
LEFT JOIN sys.objects o ON p.major_id = o.object_id
LEFT JOIN sys.database_principals dp ON p.grantee_principal_id = dp.principal_id
WHERE dp.name = 'target_user_name'
This reveals database-level permission issues that cause State 5 authentication failures.
-- Monitor active failed login attempts in real-time
SELECT
session_id,
login_name,
program_name,
client_interface_name,
login_time,
last_request_start_time
FROM sys.dm_exec_sessions
WHERE is_user_process = 1
AND login_name LIKE '%suspect_user%'
This identifies active sessions from problematic accounts to correlate with authentication errors.
-- Check authentication mode setting
SELECT
SERVERPROPERTY('IsIntegratedSecurityOnly') AS IsWindowsAuthOnly,
CASE
WHEN SERVERPROPERTY('IsIntegratedSecurityOnly') = 1
THEN 'Windows Authentication Only'
ELSE 'Mixed Mode Authentication'
END AS AuthenticationMode
This confirms the server authentication mode that may cause authentication method mismatches.
Fix Scripts
Enable Disabled SQL Server Login
-- Enable a disabled SQL Server login
ALTER LOGIN [disabled_login_name] ENABLE;
-- Verify the change
SELECT name, is_disabled
FROM sys.sql_logins
WHERE name = 'disabled_login_name';
Test in development first. This immediately enables the login and may expose the application to security risks if the account was disabled intentionally.
Reset Expired Password and Disable Policy Checks
-- Reset password and disable policy enforcement for service accounts
ALTER LOGIN [service_account_name]
WITH PASSWORD = 'NewSecurePassword123!',
CHECK_EXPIRATION = OFF,
CHECK_POLICY = OFF;
-- Confirm policy settings
SELECT name, is_policy_checked, is_expiration_checked
FROM sys.sql_logins
WHERE name = 'service_account_name';
Use strong passwords and consider this approach only for service accounts. Regular user accounts should maintain policy enforcement.
Create Database User Mapping for Existing Login
-- Create user in target database for existing server login
USE [target_database];
CREATE USER [existing_login_name] FOR LOGIN [existing_login_name];
-- Add to appropriate database role
ALTER ROLE db_datareader ADD MEMBER [existing_login_name];
-- Verify mapping
SELECT name, type_desc FROM sys.database_principals
WHERE name = 'existing_login_name';
This resolves State 5 errors where valid logins cannot access specific databases. Verify role permissions match application requirements.
Switch SQL Server to Mixed Mode Authentication
-- Enable mixed mode authentication (requires restart)
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE',
N'Software\Microsoft\MSSQLServer\MSSQLServer',
N'LoginMode', REG_DWORD, 2;
-- Verify setting (restart required for change to take effect)
SELECT SERVERPROPERTY('IsIntegratedSecurityOnly') AS CurrentMode;
Critical change requiring SQL Server service restart. Coordinate with application teams and schedule during maintenance windows.
AutoDBA generates fix scripts like these automatically, with impact estimates and rollback SQL included.
Prevention
Implement comprehensive login monitoring through Extended Events to capture authentication failures with full context including client IP addresses and application names. Create targeted XE sessions that track login failures while filtering out known benign failures from monitoring tools.
Configure appropriate password policies for SQL Server logins, especially service accounts that require CHECK_EXPIRATION = OFF and CHECK_POLICY = OFF settings. Establish password rotation procedures for service accounts before expiration dates to prevent service disruptions.
Deploy login triggers to enforce connection policies such as IP address restrictions, time-based access controls, and connection limits per login. These triggers provide additional security layers beyond standard authentication mechanisms.
Set up automated alerting for authentication failure patterns that indicate brute force attacks or compromised credentials. Implement response procedures that include temporary login disabling and security team notifications for suspicious authentication activity.
Standardize authentication modes across environments and document the rationale for Mixed Mode versus Windows Authentication choices. Create deployment checklists that verify user mappings exist in target databases before application deployments.
Establish regular audits of login permissions and database user mappings to identify orphaned accounts and excessive privileges. Use PowerShell scripts to validate login configurations across multiple SQL Server instances for consistency.
Need hands-on help?
Dealing with persistent sql server error 18456 issues across your environment? Samix Technology provides hands-on SQL Server performance consulting with 15+ years of production DBA experience.