Cannot connect to Azure SQL from Azure functions


I am trying to send some data from an Azure function to an Azure SQL DB, it seems that the function’s underlying linux image does not have PYODBC driver 18. I am using a managed identity to connect and it worked fine earlier on a linux function.

conn_string = f"Driver={{ODBC Driver 18 for SQL Server}};;DATABASE=poc"
database_conn = pyodbc.connect(conn_string, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: token_struct})            
database_cursor = database_conn.cursor()


pyodbc.Error: Can’t open lib ‘ODBC Driver 18 for SQL Server’ :azure

Asked By: Abhishek Rai



Connected to the function App linux using KUDU ssh. Printed the contents of /etc/odbcinst.ini and it showed that it had ODBC driver 18.

I changed 18 to 17 in the conn_string var and it worked.

Answered By: Abhishek Rai
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.