SQL Server Getting Error: TCP Provider: Error code 0x2746 while trying to install and use pyodbc on Ubuntu 20.04 for the first time

uttx8gqw  于 2023-03-28  发布在  其他
关注(0)|答案(1)|浏览(236)

I wanted to remotely connect to a sql-server database on my network in python. So I the installed pyodbc following the steps given on this page . It instructs to first "Install the Microsoft ODBC Drivers for SQL-Server" by following these instructions.

Having completed these steps (and only these steps) I identified the driver path and tried running this code in python.

import pyodbc as podbc
conn = podbc.connect("Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.8.so.1.1;"
                 "Server=192.XXX.XXX.XXX;"
                 "Database=db_name;"
                 "uid=xxxx;"
                 "pwd=xxxx;")

On execution I am getting the error:

pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746 (10054) (SQLDriverConnect)')

It would be helpful if you could tell me why am I getting this error and if I'm missing any steps in the installation process. Also, I am able to access the sql-server remotely through a windows machine, but whenever I'm trying to do it via an ubuntu machine I'm getting this error.

s4n0splo

s4n0splo1#

I encountered the same issue after building a docker image based on ubuntu:20.04 for AWS Sagemaker processing jobs. I resolved the error by installing a specific version of openssl, namely, 1.1.1p.

This was the command I added to my docker file:

RUN wget https://www.openssl.org/source/openssl-1.1.1p.tar.gz -O openssl-1.1.1p.tar.gz && \
tar -zxvf openssl-1.1.1p.tar.gz && \
cd openssl-1.1.1p && \
./config && \
make && \
make install && \
ldconfig

This line should be added before the command that installs the appropriate Microsoft SQL Server ODBC drivers (which was msodbcsql17 in my case)

相关问题