Search code examples
sqlcmd

SQLCMD - Username gives error of unexpected argument


I am using SQLCMD to try and connect to an SQL Server to run a script. Running this script fails with an error. This is the command I run:

SQLCMD -b -S AGAPI-PC\WORKSTATION -d Asp_TestDatabase1231 -u Test -p SQL -i "C:\WorkArea\INSTALL\INSTALL\bin\Debug\Data\SQL\Install\Asp.sql" -o "C:\WorkArea\INSTALL\INSTALL\bin\Debug\Data\Logs\SQLScriptResults_Asp.sql.log"

This is the error returned:

Sqlcmd: 'Test': Unexpected argument. Enter '-?' for help.

I have tried a number of things including the following:

  1. Checked the SQL Login credentials to ensure that they were correct,
  2. Tried using no -u and -p switch and use Windows Authentication (which connected without any issues),
  3. Tried writing it into CMD manually as I had heard copying and pasting may cause issues with certain characters not being recognized,
  4. Scoured the World Wide Web for an answer

Hopefully someone has come across this before that may be able to shed some light.


Solution

  • As Damien_The_Unbeliever stated:

    Arguments are case sensitive. -u (unicode output) != -U.(login id)

    This is also backed up by Microsoft's documentation on SQLCMD here: https://msdn.microsoft.com/en-us/library/ms162773.aspx

    Upon replacing the -u switch with -U the SQLCMD command worked without any issues.