October 2, 2014 08:55 by
Peter
PROBLEM
Error: 18456, Severity: 14, State: 38
Login failed for user 'produser'. Reason:Failed to open the explicitly specified database. [CLIET: 192.168.10.10]
or
Error: 18456, Severity: 14, State: 16.
Login failed for user 'XXXXXX'. [CLIENT: xxx.xx.x.xxx]
This is one of the most frustrating login failure errors on SQL Server. It does not mention what database the login was trying to connect to. The windows event viewer logs do not give any further information.
SOLUTION
It seems that prior to SQL Server this meant the same as State 16. But in that case you would actually see the database name to which the login was trying to connect.
To troubleshoot state 38 you need to run a profiler trace and capture the following two events.
Errors and Warnings: User Error Message Security Audit: Audit Login Failed.
Make sure you select all the columns and run the trace while the login attempt is made.
For the event “User Error Message” you should see the database name to which the connection is being attempted. Verify the database exists and verify that the user has been created in the database and has the permission to connect to the database. You should also check if this is an orphaned user and fix it.
September 9, 2014 07:33 by
Peter
If you are sysadmin, Your default database set to one of the user database. If you decide to take offline for your default database before you set default to another database. You will get the following error:
Cannot open user default database. Login failed. Login failed for user 'xx'
There are the steps below login to server to access master database and then you can set your default database.
PROBLEM
1. Connected as a sysadmin (windows authentication domain\username)
2. Connect to database server
3. Take offline your database DB_WH_Report
-- I connected
4. Disconnect to Server
When you try to connect back
ERROR
Cannot open user default database. Login failed. Login failed for user 'xx'
SOLUTION
1. Connect to Server
2. Click Option to expand Connection Propertise
3. Connect to Database Type master
4. Click Connect button