I have an alpine based docker image, with support for Python, through which I am trying to connect to Azure SQL service. Here is my simple connection code. I am getting an error when connecting to SQL server in Azure.
conn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password) pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")nect)")
import pyodbc
server = 'blah1.database.windows.net'
database = 'mydb1'
username = 'myadmin'
password = 'XXXXXX'
driver= 'ODBC Driver 17 for SQL Server'
conn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password)
c = conn.cursor()
c.execute("SELECT * FROM dbo.customers")
print(c.fetchall())
print(type(c.fetchall()))
conn.commit()
conn.close()
Here is my Dockerfile:
FROM tiangolo/uwsgi-nginx:python3.7-alpine3.8
RUN apk update
RUN apk add gcc libc-dev g++ libffi-dev libxml2 unixodbc-dev
LABEL Name=code9 Version=0.0.1
EXPOSE 8000
ENV LISTEN_PORT=8000
ENV UWSGI_INI uwsgi.ini
WORKDIR /app
ADD . /app
RUN chmod g+w /app
RUN chmod g+w /app/db.sqlite3
RUN python3 -m pip install -r requirements.txt
I am assuming that I am unixODBC will take care of the connection with SQL server in Azure or do I need to install MS SQL driver for alpine? Is there one available? I couldn't find one. Please help.
pyodbc.drivers()
? – C.Nivsapk add
and notapt-get
, among other things) – C.Nivs