DEV Community

nabbisen
nabbisen

Posted on • Updated on • Originally published at scqr.net

Microsoft SQL Server Client 2017 on Debian 9

As is a way to install the server of Microsoft SQL Server 2017, we can install the client called sqlcmd, a command line tool, as a part of mssql-tools on Debian.

The installation is simple:

$ curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
$ sudo apt update
$ sudo apt install mssql-tools
Enter fullscreen mode Exit fullscreen mode

That's all.
Then it is available:

$ /opt/mssql-tools/bin/sqlcmd
Enter fullscreen mode Exit fullscreen mode

Of course, you can add /opt/mssql-tools/bin to your PATH environment variable.

The usage is like this:

$ /opt/mssql-tools/bin/sqlcmd
Microsoft (R) SQL Server Command Line Tool
Version 17.3.0000.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]
Enter fullscreen mode Exit fullscreen mode

For example, you can execute a SQL file this way:

$ /opt/mssql-tools/bin/sqlcmd -H <db-host> -d <database> -U <db-user> -i ./xxx.sql
$ # You will be asked about <db-password>.
Enter fullscreen mode Exit fullscreen mode

If your locale is NOT English, check it before running.

Thank you for your reading :)
Happy computing.

Oldest comments (5)

Collapse
 
jlvmpepe profile image
Jose Valencia

Hello Heddi,

I am installing SQL Server Client on Debian 10 ( in Chromebook) and I am having the following error:

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : SSPI Provider: No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000).
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Cannot generate SSPI context.

Can you have any tips to resolve it?

Thanks in advance.

Pepe

Collapse
 
nabbisen profile image
nabbisen

Hello Jose,

Sorry, but I haven't met the case.
Do you use any domain name to connect to your server? I used just 127.0.0.1 then.

Microsoft seemed to write about the error ("Last Updated: Jan 29, 2019"):
support.microsoft.com/en-us/help/8...
I'm happy if this would help you.

Collapse
 
zeshable profile image
zeshable

Hello when I run sudo apt install mssql-tools after doing all the steps, I get this:
Reading package lists... Done

Building dependency tree

Reading state information... Done

Some packages could not be installed. This may mean that you have

requested an impossible situation or if you are using the unstable

distribution that some required packages have not yet been created

or been moved out of Incoming.

The following information may help to resolve the situation:

The following packages have unmet dependencies:

mssql-tools : Depends: msodbcsql17 (>= 17.3.0.0) but it is not going to be installed

E: Unable to correct problems, you have held broken packages.

Thanks.

Collapse
 
zeshable profile image
zeshable

Nevermind I got it but now ran into a new problem when running /opt/mssql-tools/bin/sqlcmd, I get the following error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

Collapse
 
nabbisen profile image
nabbisen

Hi, zeshable. Sorry for my late reply.

Hmm... I have never met the 0x2479 error.

Server is not found or not accessible.
Check if instance name is correct and if SQL Server is configured to allow remote connections.

Your server seems missing from client.
Although I don't know why.., it might be because of network or firewall?