By Hally | Last Updated
After you install Microsoft SQL Server 2016/2014/2012/2008/2005/2000, and you try to connect to server that is running SQL Server, probably you receive one of following error messages.
However, what lead to these errors occurring? Now let's learn to check these login failed error details and fix them in this article.
While you receive error 18456/18452 message, please check error state in SQL Server error log.
Msg 18456, Level 14, State 1, Server <server name>, Line 1
Login failed for user '<user name>'
We should know that the 'State' will always be shown to be '1' regardless of the nature of the problem. To determine the true reason for the SQL Server login failure, the administrator can look in server's error log where a corresponding entry will be written.
View the entry and just need to pay attention to the "State", which the server will accurately set to reflect the source of the problem. Refer to common error states and their descriptions in following table, you would find the real reason for failed logining SQL Server.
ERROR STATE |
ERROR DESCRIPTION |
2 and 5 |
Invalid userid |
6 |
Attempt to use a Windows login name |
7 |
Login disabled and password mismatch |
8 |
Password mismatch |
9 |
Invalid password |
11 and 12 |
Valid login but server access failure |
13 |
SQL Server service paused |
18 |
Change password required |
While you receive SQL Server failed login error 4062/4064, you should look for reason why cannot open default database.
As is known, each user has a default database. And it is used automatically when you connect to computer that is running Microsoft SQL Server, and you do not specify a login database. However, if it is unavailable when connected, you may not be able to connect. Instead, you receive error 4062/4064 message.
Default database becomes unavailable probably because the database:
"Login failed for user" would occur if the user tries to login with credentials without being validated. Now we will introduce some situations when there is no user credentials for SQL Server logon and how to solve SQL Server login problem.
Situation 1: The login may be a SQL Server login but the server only accepts Windows Authentication.
To login SQL Server successfully, you should change to login SQL Server with Windows Authentication mode and enable Mixed Authentication mode or SQL Server Authentication mode.
Situation 2: You are trying to connect by using SQL Server Authentication but the login used does not exist on SQL Server.
In order to make SQL Server login with user, please confirm that you have a login user. If not, create new login in SQL Server Books Online.
Situation 3: The login may use Windows Authentication but the login is an unrecognized Windows principal.
An unrecognized Windows principal means that Windows can't verify the login. This might be because the Windows login is from an untrusted domain. To resolve this issue, verify that you are logged in to the correct domain.
Situation 4: The login user password is valid or incorrect, or the password is changed.
If it is just because of user password incorrect or invalid, you can reset user password with SQL Password Genius, and then login SQL Server with new password again.
Situation 5: The login is disabled.
You should need to enable SQL Server login user or enable SQL Server authentication mode after connecting to server with Windows authentication mode.
Situation 6: The login is valid but server access is failed.
Probably you have no admin privileges to server, or Windows Firewall has not allowed SQL Server access. So you can try to get administrator rights or configure Windows Firewall to allow SQL Server access.
To fix SQL Server login error 4062/4064, please specify an available, valid database as user's default database. So while default database is connected automatically, successful connection can be guaranteed.
Step 1: Run Command Prompt as administrator.
Step 2: Set default database for login user by one of following methods.
2-1 If SQL Server login uses Windows authentication mode, run command below and press Enter.
sqlcmd –E -S InstanceName –d master
2-2 If SQL Server login uses SQL Server authentication to connect to instance, run command below.
sqlcmd -S InstanceName -d master -U SQLLogin -P Password
Step 3: At the sqlcmd prompt, type the following, and then press ENTER.
ALTER LOGIN SQLLogin WITH DEFAULT_DATABASE = AvailDBName
Step 4: At the sqlcmd prompt, type GO, and then press ENTER.
Related Articles: