Installing ODBC Driver on Heroku

与世无争的帅哥 提交于 2020-07-09 03:12:32

问题


I'm trying to use pyodbc to connect to my MSSQL database hosted on azure, and while it works locally, I cannot get it to work when I push the changes to Heroku. I'm running Windows. This is the error it gives me:

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

This is how I start the connection:

cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};
       SERVER=serverurl;
       DATABASE=db;
       UID=user;
       PWD=password')

This is my Aptfile where I included a download link to the driver for Heroku:

unixodbc
unixodbc-dev
python-pyodbc
libsqliteodbc
https://packages.microsoft.com/ubuntu/16.04/prod/pool/main/m/msodbcsql/msodbcsql_13.1.9.2-1_amd64.deb

And my requirements.txt:

...
pyodbc==4.0.24

I even have a buildpack installed (https://github.com/heroku/heroku-buildpack-apt). From what I understand, the driver isn't present on Heroku's end, and as such it can't locate it.

If this really is the case, how can I get Heroku to download the driver? I've tried placing the download link in the Aptfile as seen above, but it doesn't seem to work.


回答1:


I believe this can be solved with the same methodology as a similar question Python cant find ODBC Driver on Heroku after setting everything.

tldr: the solution was to precompile ODBC Driver 17 for SQL Server on an Ubuntu 18.04 environment and copy the required driver files over to Heroku via this buildpack https://github.com/matt-bertoncello/python-pyodbc-buildpack.git. The same process sbould be able to work by precompiling a ODBC Driver 13 on an Ubuntu 16.04 environment.



来源:https://stackoverflow.com/questions/53003687/installing-odbc-driver-on-heroku

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