azure-functions-python-worker: Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0)

I developed a function which inserts data to Azure SQL Server when an excel file is uploaded to Azure storage container. Function works perfectly fine on local machine. After testing locally I deployed the function using below command:-

func azure functionapp publish ‘functionname’ --build-native-deps --additional-packages “python3-dev libevent-dev unixodbc-dev” --force --no-bundler

On Uploading file to storage account after deployment to Azure, I see below error in logs:-

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 “/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py”, line 288, in _handle__invocation_request self.__run_sync_func, invocation_id, fi.func, args) File “/root/.pyenv/versions/3.6.8/lib/python3.6/concurrent/futures/thread.py”, line 56, in run result = self.fn(*self.args, **self.kwargs) File “/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py”, line 347, in __run_sync_func return func(**params) File “/home/site/wwwroot/ProcessExcelApp1EU0304/init.py”, line 44, in main cnxn=pyodbc.connect(dbconnection)

Please provide the following:

  • Timestamp:2019-03-05 19:05:57.735
  • Function App name:ProcessExcelApp1EU0304
  • Function name(s) (as appropriate):ProcessExcelApp1EU0304
  • Core Tools version: Azure Functions Core Tools (2.4.317 Commit hash:63e1996b6c281079427e7c9b8a0a1c633988a195) Function Runtime Version: 2.0.12285.0

Repro steps

Provide the steps required to reproduce the problem:

  1. Upload a file to storage account container configured to trigger the function from
  2. Data should get inserted to Azure SQL Server DB url for which is setup in application settings

Expected behavior

Function should read the excel file and then data should get inserted to Azure SQL Server DB url for which is setup in application settings

Actual behavior

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 “/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py”, line 288, in _handle__invocation_request self.__run_sync_func, invocation_id, fi.func, args) File “/root/.pyenv/versions/3.6.8/lib/python3.6/concurrent/futures/thread.py”, line 56, in run result = self.fn(*self.args, **self.kwargs) File “/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py”, line 347, in __run_sync_func return func(**params) File “/home/site/wwwroot/ProcessExcelApp1EU0304/init.py”, line 44, in main cnxn=pyodbc.connect(dbconnection)

Known workarounds

Have to run it locally for testing

Related information

Provide any related information

  • Links to source
  • Contents of the requirements.txt file
  • Bindings used

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (2 by maintainers)

Most upvoted comments

I am using Windows 10 machine to develop locally and deployed after testing locally.

Found a work around today afternoon. If I replace {ODBC Driver 13 for SQL Server} to {ODBC Driver 17 for SQL Server} in connection string then it is working fine. But I am not really sure if this is the right way to do it because Azure SQL DB connection string has {ODBC Driver 13 for SQL Server} in connection string.

This is fixed in the latest release (2.6.1048 <=) of azure-functions-core-tools . https://github.com/Azure/azure-functions-core-tools/issues/1211 for more information.

Today April 23, 2019, I tried to spin up a new Azure function 2.0 on OS-type Linux and runtime Python 3.6 When I add pyodbc in requirements file, I am unable to publish the app (without it, the app publishes) I am using --build-native-deps and running docker locally on my Windows 10 box.

This is the error I get, Building wheels for collected packages: pyodbc, pycparser Building wheel for pyodbc (setup.py) ... error Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-0g7v0744/pyodbc/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-cw8pu7rd --python-tag cp36: running bdist_wheel running build running build_ext building 'pyodbc' extension creating build creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/src gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.23 -I/usr/local/include/python3.6m -c src/textenc.cpp -o build/temp.linux-x86_64-3.6/src/textenc.o -Wno-write-strings unable to execute 'gcc': No such file or directory error: command 'gcc' failed with exit status 1

Any help? Something changed or I am missing something

I assume you also use os-type Linux. Did you test the function locally on Windows or Linux. But regardless one thing is that pyodbc may not install seamlessly (i.e. just with pip) on Linux VM where Azure function will run and hence the issue. I am also interested in a solution to this problem.