Pyodbc Connection error when trying to connect to remote sql server from azure docker container

Viewed 523

Azure Docker Container Error:

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

The connection string is:

conn = pyodbc.connect('Driver={FreeTDS};SERVER=server_name,1433;DATABASE=dbname;UID=username;PWD=password')

Odbcinst.ini

[FreeTDS]
Description=FreeTDS Driver 
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so 
Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

DockerFile

FROM python:3.8

WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app


# install FreeTDS and dependencies
RUN apt-get update \
 && apt-get install unixodbc -y \
 && apt-get install unixodbc-dev -y \
 && apt-get install freetds-dev -y \
 && apt-get install freetds-bin -y \
 && apt-get install tdsodbc -y \
 && apt-get install --reinstall build-essential -y

# populate "ocbcinst.ini"
RUN echo "[FreeTDS]\n\
Description = FreeTDS unixODBC Driver\n\
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so\n\
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so" >> /etc/odbcinst.ini

RUN pip install --trusted-host pypi.python.org -r requirements.txt

EXPOSE 80
# Run app.py when the container launches
CMD ["python", "app.py"]

When I am running the container on local machine, it is running. But when I am trying to do so on azure platform I am getting this error. Any help would be really appreciated.

0 Answers
Related