mssql-cli cannot connect to remote server

911 views Asked by At

I am trying to connect to a remote SQL Server with mssql-cli, I use this command:

/usr/local/bin/mssql-cli -S server -U admin -d db -P ****

and I get this error:

Error message: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)

However, I am able to connect using sqsh with no problem:

sqsh -S server -U admin -D db -P ****

Since I can connect with sqsh but not mssql-cli, and I am able to connect to a local instance of SQL Server, I'm not sure where to go from here.

1

There are 1 answers

0
iateadonut On BEST ANSWER

I found the answer here: https://askubuntu.com/questions/1284658/how-to-fix-microsoft-odbc-driver-17-for-sql-server-ssl-provider-ssl-choose-cli

The answer is to update to the latest openssl:

wget https://www.openssl.org/source/latest.tar.gz -O openssl-1.1.1i.tar.gz
tar -zxvf openssl-1.1.1i.tar.gz
cd openssl-1.1.1i
./config
make
sudo make install
openssl version
sudo ldconfig

I also installed mssql-tools and unixodbc-dev - although I don't know if that had anything to do with it:

https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-ver15

These docs are for 16.04; so you have to change that to 20.04 if you're using mint 20 or ubuntu 20.04 like I am:

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

sudo apt install mssql-tools unixodbc-dev odbcinst1debian2 msodbcsql17 unixodbc libodbc1

It installs to /opt/mssql-tools/bin, so make sure add /opt/mssql-tools/bin/ to your PATH environment variable in a bash shell.