Understanding SQL Server error 18456

I came across an odd problem with SQL Server Express.  We have a test server with various versions of SQL Server installed for QA to use.   Of the QA techs was unable to connect to the instance of SQL Server Express when he used a SQL Server login.  The code was not returning an error error code, so I decide to take a look at it.

I tried connecting to Express from MS SQL Server Management Studio under that account.  SSMS returned an 18456 error, basically it couldn’t connect.  That was just slightly more useful than what I had before, but it provide two things.  It ruled out the app as cause of the problem, and it gave something that I could google with.

The best match I got was Understanding “login failed” (Error 18456) error messages in SQL Server 2005, on the SQL Protocols blog.  Basically, the error 18456 error is purposely vague to prevent nasty people from trying to hack into your server.  To figure out why the login failed, you need the “error state”.  Error state is not returned to the client, but it’s written to the log file.  That file will be in the LOGS folder of that instance of SQL Server under the name ERRORLOG.   From the log file, you’ll get more information about why the login failed:

2007-04-10 09:54:45.14 Logon       Error: 18456, Severity: 14, State: 8.
2007-04-10 09:54:45.14 Logon       Login failed for user 'youridhere'. [CLIENT:]

From the first line, we get the eror state.  Yay, it’s 8.  So what does that mean?  The states are documented in the blog posting reference above, but I couldn’t find it in my copy of the BOL.  It is documented in the online version (and probably in the latest BOL) at ‘.”” href=”http://msdn2.microsoft.com/en-us/library/ms366351.aspx”>SQL Server 2005 Books Online.  Here are the documented states:

State Description


User ID is not valid.


User ID is not valid.


An attempt was made to use a Windows login name with SQL Server Authentication.


Login is disabled, and the password is incorrect.


The password is incorrect.


Password is not valid.


Login is valid, but server access failed.


Login is valid login, but server access failed.


Password must be changed.

Any other error state is considered to be an internal error.

So it boils down to the password being incorrect, which in this case it was.