question

HamishCox-7573 avatar image
0 Votes"
HamishCox-7573 asked ryanchill commented

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

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: http://sqlalche.me/e/dbapi)

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-webapps
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SnehaAgrawal-MSFT avatar image
0 Votes"
SnehaAgrawal-MSFT answered SnehaAgrawal-MSFT edited

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.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NguyenKelvin-5500 avatar image
0 Votes"
NguyenKelvin-5500 answered ryanchill commented

@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.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@NguyenKelvin-5500 Could you please send an email to AzCommunity[at]Microsoft[dot]com referencing this issue, we would like to work closer with you on this matter.

0 Votes 0 ·

Has there been any resolution to this issue? I find myself in the exact same situation.

See my question here: https://docs.microsoft.com/en-us/answers/questions/484230/can39t-ssh-in-to-azure-flask-web-services-app-to-i.html

0 Votes 0 ·

It's been a while so I don't fully remember, but I don't think any of these answers worked (best to try them anyway though). I ended up moving my app to AWS instead of Azure.

1 Vote 1 ·
Show more comments
RaghavMundhra-3636 avatar image
0 Votes"
RaghavMundhra-3636 answered RaghavMundhra-3636 edited

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.

 pyodbc.connect(‘Driver={FreeTDS};SERVER=’+server+’;DATABASE=’+database+’;UID=’+username+’;PWD=’+password)

This works for me.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.