How to use ODBC driver in Linux App Service via pyodbc to connect to an Azure DB?

Hamish Cox 6 Reputation points

Hi, I'm trying to set up a Python (flask) App Service that accesses an Azure SQL Server. In order to access the server, the app service needs the ODBC drivers installed.

Error from SQLAlchemy:
2020-05-07T23:23:47.256046274Z sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)")
2020-05-07T23:23:47.256050074Z (Background on this error at:

I have tried using 'ODBC 13 for SQL Server' as the driver, along with trying to install unixODBC using a prebuild script, but neither helped.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,334 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 20,241 Reputation points

    Thanks for asking question! Could you please try with ODBC Driver 17 for deploying a python flask app on Linux based app services using pyodbc to connect to an Azure DB.

     pyodbc.connect(‘Driver={ODBC Driver 17 for SQL Server};SERVER=’+server+’;DATABASE=’+database+’;UID=’+username+’;PWD=’+password)

    Let me know if issue persists.

    0 comments No comments

  2. Nguyen, Kelvin 1 Reputation point

    @SnehaAgrawal-MSFT this won't work since by default the driver is not installed.

    I've tried various way of installing MSSQL Driver for Linux App Service but it just never works.

  3. Raghav Mundhra 1 Reputation point

    The installation of Pyodbc should not create any issue, but while using it, do not use ODBC Driver for SQL server on Linux App services. Try with FreeTDS driver instead. FreeTDS drivers are already installed on Azure Linux App Services, so you don't need to install them separately.


    This works for me.