Skip to content Skip to sidebar Skip to footer

Error Trying To Connect To A Sql Server Using Sqlcmd (from Ubuntu Command Line)?

I am finding some problem trying to connect to a SQL Server instance from an Ubuntu machine using sqlcmd. So I installed sqlcmd as explained here: https://docs.microsoft.com/it-it/

Solution 1:

-S MY_SERVER_IP\ESB_WSO2_USER_DB means the IP of the server, and the name of the instance. Windows Hosts can run multiple instances of SQL Server, and when they do, latter instances need to be given a different name to the default instance name (MSSQLSERVER) and run on a different port. As a result you can specify the name afterwards, rather than the port (if you have named servers running). For example SRVSQLHost\DevInstance would connect the to instance DevInstance on the server SRVSQLHost; not the database DevInstance on the instance MSSQLSERVER on the host SRVSQLHost.

You pass the name of the database using the -d switch. If you run simply sqlcmd (in Bash, not Powershell, where you need to use sqlcmd -?) you'll see the input switches:

:~$ sqlcmd
Microsoft (R) SQL Server Command Line Tool
Version 17.4.0001.1 Linux
Copyright (c) 2012 Microsoft. All rights reserved.

usage: sqlcmd            [-U login id]          [-P password]
  [-S server or Dsn if -D is provided] 
  [-H hostname]          [-E trusted connection]
  [-N Encrypt Connection][-C Trust Server Certificate]
  [-d use database name] [-l login timeout]     [-t query timeout]
  [-h headers]           [-s colseparator]      [-w screen width]
  [-a packetsize]        [-e echo input]        [-I Enable Quoted Identifiers]
  [-c cmdend]
  [-q "cmdline query"]   [-Q "cmdline query" and exit]
  [-m errorlevel]        [-V severitylevel]     [-W remove trailing spaces]
  [-u unicode output]    [-r[0|1] msgs to stderr]
  [-i inputfile]         [-o outputfile]
  [-k[1|2] remove[replace] control characters]
  [-y variable length type display width]
  [-Y fixed length type display width]
  [-p[1] print statistics[colon format]]
  [-R use client regional setting]
  [-K application intent]
  [-M multisubnet failover]
  [-b On error batch abort]
  [-D Dsn flag, indicate -S is Dsn] 
  [-X[1] disable commands, startup script, environment variables [and exit]]
  [-x disable variable substitution]
  [-? show syntax summary]

Note that some switches available on Windows Powershell are not available in Bash and Powershell for Linux; such as parameters.

So, for what you have you want:

sqlcmd -S MY_SERVER_IP -d ESB_WSO2_USER_DB -U YOUR_LOGIN_NAME

(I assume you need to pass the -U switch, unless you have configured kerboros on your Ubuntu instance, but you didn't mention it, so I assumed not. Note that the LOGIN for -U must be a SQL Authentication login, not an AD login.)

Post a Comment for "Error Trying To Connect To A Sql Server Using Sqlcmd (from Ubuntu Command Line)?"