1

Getting the following error - when trying to view a Flask web app that is deployed to Azure using pyodbc:

2019-09-03T14:25:35.575624728Z conn = pyodbc.connect('Driver={SQL Server};'
2019-09-03T14:25:35.575857932Z pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)")

Can anyone advise, What I would need to do to fix this? Works fine on my local machine btw.

Thanks..

whoami - fakeFaceTrueSoul
  • 17,086
  • 6
  • 32
  • 46
  • Im not that familiar with Azure, but its looks like you need to install the 'SQL Server' driver? – erncyp Sep 03 '19 at 15:03
  • 1
    @erncyp - Right idea, except that the ODBC driver named "SQL Server" is ancient and is only included in a standard Windows distribution. The most current "ODBC Driver 17 for SQL Server" is available for both Windows and non-Windows platforms. – Gord Thompson Sep 03 '19 at 15:50

2 Answers2

1

Make sure you have installed pyodbc package on Azure Web App.

Then form the connection string and connect to SQL DB:

driver= '{ODBC Driver 17 for SQL Server}'
conn_str = 'DRIVER=' + driver + \
                ';SERVER=' + serverName + \
                ';DATABASE=' + dbName + \
                ';UID=' + uname + \
                ';PWD=' + pwd
sql_conn    =   pyodbc.connect(conn_str)

More Information on Configuring Environment on Azure.

Anish K
  • 798
  • 4
  • 13
0

I had the same issue after trying many methods this one worked for me.

If you are using Linux version of azure web app simply ssh to you web app and run the below command:-

  1. apt-get update

  2. apt-get install g++

  3. apt-get install unixodbc-dev

  4. pip install pyodbc

For More Info check the Debian Stretch Part in the below document :- https://github.com/mkleehammer/pyodbc/wiki/Install

cbuchart
  • 10,847
  • 9
  • 53
  • 93