1

Not able to connect with Azure SQL Server through Docker container using the following code -

Based of url - Cannot connect to Azure SQL using an alpine docker image with Python

I tried different drivers but FreeTDS is not at all working.

pyodbc.OperationalError: ('08S01', '[08S01] [FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist (20009) (SQLDriverConnect)')

odbcinst.ini 
[FreeTDS]
Description=FreeTDS Driver 
Driver=/usr/lib/libtdsodbc.so
Setup=/usr/lib/libtdsS.so
  • How are you trying to connect? With `isql` or `tsql`? If you're trying in Python, what's the code you're using for your connection string with `pyodbc`? – FlipperPA Aug 14 '19 at 09:37

1 Answers1

0

Due to there are not msodbcsql17 and mssql-tools packages for Apline Linux as the offical document Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS list, I'm afraid you can not only use freetds and unixodbc-dev to connect Azure SQL Database v17.

As the figure below, you can see the /etc/odbcinst.ini content in my Ubuntu Linux. Now, to connect Azure SQL Database v17 you created in Azure Portal requires to use a specified odbc library libmsodbcsql-17.3.so.1.1.

enter image description here

So the only solution is to switch to use pymssql package in Python to connect, please refer to the offical document Python SQL Driver - pymssql to add the required content of freetds-dev and pymssql into your Docker file.

apk add freetds freetds-dev
pip install pymssql

Hope it helps.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43