How to access ODBC Driver on Azure App service

懵懂的女人 提交于 2020-12-23 11:41:05

问题


I'm trying to run a Django (3.0) app on Azure App Service in Linux, connected to an Azure SQL Database. In my staging App Service instance, this works perfectly, however, when I set up my production instance on a different Azure account, my Django app can no longer access the database.

When I hardcoded the ODBC Driver 17 into database settings, I got this error in my Oryx build logs:

pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

When I switched to the non-hardcoded version suggested here, I got this error:

    'driver': sorted(pyodbc.drivers()).pop(),
IndexError: pop from empty list

How does one go about installing an ODBC Driver on Azure App Service?

EDIT: I am not using the Docker deploy option. I am deploying source code directly from Github.


回答1:


I have tested it and it works for me.

Open ssh to you web app and run the below command:-

  1. apt-get update
  1. apt-get install g++
  1. apt-get install unixodbc-dev
  1. pip install pyodbc

Then we can use the privacy mode, or visit the website after clearing the cache. You can try to refresh a few more times and you will find that the website is back to normal.

Previous I said you can try to use venv, after I tested, I found it doesn't need to use it. Follow my step to run the command, you webapp will be ok.



来源:https://stackoverflow.com/questions/64640016/how-to-access-odbc-driver-on-azure-app-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!