Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I can't seem to authenticate to my SQL server using the following command:

sqlcmd -S myserver -d mydatabase -U user -P password

It always says, error: 18456, state 1: login failed for "domain\username"

What is weird is that if I test my connection through ODBC with the same credentials it authenticates fine. In the management studio the account I'm using has the dbo_owner privileges on the instance and the database. Also I connect to the instance using those same credentials.

In my event log I also have this error:

Login failed for 'domain\username'. Reason: Failed to open the explicitly specified database [CLIENT MY_IPADDRESS]

I'm no SQL expert and could use some help troubleshooting this if possible.

share|improve this question
    
There should be an error in the event log as well that looks like Error: 18456, Severity: #, State: #. What's that one look like? You will always receive a state 1 error from the command line. The state error indicates the source of the problem. –  cole Oct 31 '13 at 18:34
    
@Cole there is no state field in the event log. The only other info is level 4 and task 0 –  inquisitor Oct 31 '13 at 18:39

1 Answer 1

up vote 3 down vote accepted

You can't use a Windows login with the -U parameter. -U is for SQL logins. If you want to connect as the currently logged in Windows user use the -E parameter to indicate you want to use a trusted connection.

sqlcmd -S myserver -d mydatabase -E

If you want to connect as a different windows user then you can run your shell (cmd, powershell, etc) as that user and use the above command.

share|improve this answer
    
Doing this still gives me the same error in addition to a new error MSG 4060, Level 11, State 1 –  inquisitor Oct 31 '13 at 18:42
    
@inquisitor Can you add the exact command you're typing in? Your id has access to the database? –  squillman Oct 31 '13 at 19:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.