Unable to query azure sql database from azure python function using pyodbc

mani 1 Reputation point

Hi -

My use-case is as follows:I have a http trigger azure python function. This function should query from azure sql database.
I have drafted a python azure function and used pyodbc package (added in requirements.txt) to query the azure database with appropriate connection string. However, at the time of execution, I am getting below driver not found error. Can you help? How am I supposed to install a driver in a serverless platform like azure functions? Let me know if you have any other way to query azure database from python azure functions. thanks!

Error message below:
Result: Failure Exception: Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) (SQLDriverConnect)") Stack: File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 458, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 701, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper result = function(**args) File "/home/site/wwwroot/finaltemp/init.py", line 20, in main conn = pyodbc.connect(connection_string)

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
2,598 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. lukemurraynz 2,926 Reputation points Microsoft MVP

    Replace the ODBC from 13 to 17 and try that - ie {ODBC Driver 17 for SQL Server}.