I am having a mssql server running in docker, I want to connect the server using sqlalchemy
For connecting, I am using this connection string,
engine = create_engine(
'mssql+pyodbc:///?odbc_connect=%s' % (
urllib.parse.quote_plus(
'DRIVER={/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so};SERVER=localhost;'
'DATABASE=ap;UID=sa;PWD=admin@123;port=1433;'
)),
)
For this, I got this error,
sqlalchemy.exc.DBAPIError: (pyodbc.Error) (‘01000’, "[01000] [unixODBC][Driver Manager]Can’t open lib ‘/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so’ : file not found (0) (SQLDriverConnect)")
Then, I figured that this file is missing. How to get libtdsodbc.so
file
I am using Ubuntu 22.04.2 LTS
the docker mssql server is 2017,
in docker status, the port is shown as 0.0.0.0:1433->1433/tcp, :::1433->1433/tcp
Thanks
2
Answers
You can install the Microsoft ODBC Driver for SQL Server on Linux by following the instructions here:
Install the Microsoft ODBC driver for SQL Server (Linux)
You can install libtdsodbc.so using
although the Ubuntu 22.04 repo installs a rather old version, 1.3.6 (released 17 months ago), whereas the most recent stable release is currently 1.3.18 (released 7 weeks ago).
Also, SQLAlchemy is not tested with FreeTDS ODBC for the
mssql+pyodbc://
dialect, so you may be happier in the long run if you use Microsoft’s ODBC driver for SQL Server as suggested in the other answer.