Can't access sqlcmd using username password

21,402

Solution 1

It is possible that you have multiple server instances on your computer. Some MS products install the SQL Server Developer edition unless you explicitly tell it not to. So, unless you are explicitly telling sqlcmd which instance to connect to, it may be connecting to something you aren't expecting.

sqlcmd -S servername -d database name -U id

Solution 2

Try this:

-S MyServer\MyInstance

and for the database as well

Share:
21,402
Admin
Author by

Admin

Updated on July 12, 2020

Comments

  • Admin
    Admin almost 4 years

    I am new to SQL Server. Please help me to fix.

    I have created a user with password in SQL Server Management Studio (2008 R2). When I use sqlcmd with this user, sqlcmd says

    C:\Console2>sqlcmd -U admin
    Password: 
    

    Msg 18456, Level 14, State 1, Server machinename, Line 1
    Login failed for user 'admin'.

    I can access the server with this user using SQL Server Management Studio.

    P.S

    • I have two instance of SQL Server Management Studio (2008 R2 and 2012). I can access that user from both version of SQL Server Management Studio.
    • Whenever I connect using sqlcmd and execute select @@version query, it always says 2012, even I am connecting 2008 R2's sqlcmd.