mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.88k stars 562 forks source link

pyodbc + Azure Function Apps, and 2 "Can't open lib 'ODBC Driver 18 for SQL Server" error #1136

Closed SebastianDeChiara closed 1 year ago

SebastianDeChiara commented 1 year ago

I'm stuck in an error which I've been researching for a while now. I have looked at all the related issues and have found no solution within them.

I have Python code that I want to use in a Function App with a time trigger that runs every day at 06:00. The code:

  1. Calls an API, downloads data.

  2. Cleans the data.

  3. Connects to a database using pyodbc module.

  4. Inserts data into the database.

I then create the function app, configure it, and, locally, it's running perfectly, executing the code everyday at 06:00.

Then I create a resource and deploy the function app on Azure. The function executes properly at the configured time. However, when it runs, I get the error.

https://pastebin.com/FWBECeWq

This is the overview of the function app:

https://imgur.com/a/XDetHzk

Could it be related to the fact that the application is hosted on Linux and I'm using pyodbc driver for Windows?

keitherskine commented 1 year ago

It's possible the Function App doesn't have ODBC Driver 18 installed. Perhaps it only has ODBC Driver 17, in which case you could try using that instead, i.e. in your code, do something like this: pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server} ...

To see what drivers are available to pyodbc, try using pyodbc.dataSources() and pyodbc.drivers(), i.e.:

import pyodbc
print(pyodbc.dataSources())
print(pyodbc.drivers())
SebastianDeChiara commented 1 year ago

Thank you, this was useful to know what drivers the virtual machine has. This helped me solve the issue.