sqlcmd Login failed for user

Mindea 20 Reputation points
2024-07-29T14:23:06.8933333+00:00

I just set up SQL Server Express a Windows PC and added a couple SQL user logins, a database, a linked database, and a stored procedure. I can login via SSMS (on the same computer) with the SQL user creds, connect to the linked database, and run the local stored procedure. No problem.

Now I want to connect via sqlcmd command, but it fails on the login. Again, doing this on the same PC.

sqlcmd -S TH-DBREP01\sqlexpress -U xxxxx -P 'xxxxxxx'

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'Guy_RW'

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,012 questions
{count} votes

Accepted answer
  1. Zahid Butt 956 Reputation points
    2024-07-29T16:30:26.16+00:00

    Hi,

    You may connect with below commands:

    Using windows authentication:

    sqlcmd -S servername/instancename -E

    or SQL server authentication:

    sqlcmd -S servername/instancename -U Username -P Password

    Further you may take help from :https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-utility?view=sql-server-2017&tabs=go%2Cwindows&pivots=cs1-bash


2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Erland Sommarskog 112.7K Reputation points MVP
    2024-07-29T22:07:19.2233333+00:00

    Look in the SQL Server errorlog, which you find in C:\Program Files\Microsoft SQL Server\MSSQL16.SQLEXPRESS\MSSQL\LOG\ERRORLOG. There should be a message that details why the login failed. If it says that the password is wrong, Look at Viorel's post. The problem may be the single quotes.

    Also, make sure that you change the password, having you have exposed it here!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.