Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

What Is SQL Server Error 18456 and How to Fix It

Find the reason for the "Login failed for user" error and fix credentials, permissions or authentication mode.

Fixing Errors3 min read12 steps

What is error 18456

Error 18456 means "Login failed for user". SQL Server received the connection, but it refused the login. The message to the client is kept vague on purpose. The real reason is in the SQL Server error log as a State number.

Find the real reason

Check the error log and Event Viewer

  1. In SQL Server Management Studio open Management > SQL Server Logs > Current.
  2. Search for 18456.
  3. Read the line with the State value, for example Error: 18456, Severity: 14, State: 8.

You can also read the logs in the Windows Event Viewer.

Common state values:

StateMeaning
2 or 5The user name is not valid
6A Windows login was used with SQL authentication
7The login is disabled and the password is wrong
8The password is wrong
9The password is not valid
11 or 12The login is valid but has no permission to connect
13The SQL Server service is paused
16The login cannot open the default database
18The password must be changed
38 or 40The database requested in the login cannot be opened
58SQL authentication is used but the server accepts only Windows authentication

Fixes

1. Check the user name and password

  • Type them again. Watch for caps lock, extra spaces and the right domain (DOMAIN\user).
  • Reset the password if you are not sure:
ALTER LOGIN [username] WITH PASSWORD = 'NewStrongPassword';

2. Check that the login is enabled and not locked

ALTER LOGIN [username] ENABLE;
ALTER LOGIN [username] WITH PASSWORD = 'NewStrongPassword' UNLOCK;

3. Check the authentication mode

If you use SQL logins but the server accepts only Windows logins, the login fails (state 58).

  1. In SSMS right-click the server and choose Properties > Security.
  2. Choose SQL Server and Windows Authentication mode.
  3. Restart the SQL Server service.

4. Check the permissions

  • Make sure the login exists under Security > Logins.
  • Make sure it has CONNECT SQL permission and access to the database.
  • Map the user to the database:
USE MyDatabase;
CREATE USER [username] FOR LOGIN [username];
ALTER ROLE db_datareader ADD MEMBER [username];

5. Check the default database

If the default database is gone or offline, set another one:

ALTER LOGIN [username] WITH DEFAULT_DATABASE = master;

6. Check the network and the server name

Connect to the right instance (SERVER\INSTANCE), and check that the SQL Server Browser service and TCP/IP are on if you use a named instance.

Prevent the error

  1. Use strong, unique passwords and store them safely.
  2. Monitor the logs for repeated failed logins. They can show an attack.
  3. Set a lockout policy for failed attempts.
  4. Choose the authentication mode that fits your needs. Windows authentication is safer when it is possible.
  5. Keep SQL Server updated.
  6. Review the permissions from time to time and give only the rights that are needed.

Quick recap

  • Read the State in the SQL Server log to find the exact reason.
  • Fix the password, the authentication mode or the permissions.