How do I test connection from Linux to Microsoft SQL Server?

Solution 1:

I think the simplest would be to try to telnet to MS SQL server from the command line:

$ telnet <server-name-or-ip> 1433

If your connection was successful the screen goes blank, otherwise you'll see something like "Connecting to server-name-or-ip... Could not open connection to the host, on port 1433: Connect failed."

Solution 2:

On the remote Microsoft SQL Server instance: make sure port TCP 1433 is open in the firewall.

On the Ubuntu Server instance install the mssql-tools as described here: https://www.microsoft.com/en-us/sql-server/developer-get-started/php/ubuntu

sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17 mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
sudo apt-get install unixodbc-dev

You can then run a test query - you'll be prompted for password:

[user@lnx01 ~ $] sqlcmd -S <remoteip> -U <user> -p -Q "SELECT @@VERSION"
Password: 

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64) 
    Aug 22 2017 17:04:49 
    Copyright (C) 2017 Microsoft Corporation
    Express Edition (64-bit) on Windows Server 2016 Standard 10.0 <X64> (Build 14393: )


(1 rows affected)