Share via

Issue Connecting Python Web App to Database via pyodbc

Robbie Morton 20 Reputation points
2026-01-11T18:26:11.94+00:00

I’m experiencing issues connecting my web application to its database. The backend is written in Python (running on the Python 3.14 stack) and uses pyodbc for database connectivity. Recently, when deploying the application, the web app is unable to locate any installed ODBC drivers. As a result, I have to manually install the required driver each time after deployment.

When the application attempts to create the database connection, it fails with the following error:

ERROR:root:Failed to create Azure SQL connection: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 18 for SQL Server' : file not found (0) (SQLDriverConnect)")

Has anyone encountered this issue before, or is there a recommended way to ensure the correct ODBC driver is available and persistently configured during deployment?

Azure App Service
Azure App Service

Azure App Service is a service used to create and deploy scalable, mission-critical web apps.

0 comments No comments

Answer accepted by question author

Michele Ariis 7,215 Reputation points MVP Volunteer Moderator
2026-01-12T08:44:13+00:00

Hi, this usually happens because the Linux App Service image doesn’t ship with ODBC Driver 18, and anything you install manually doesn’t persist across updates/re-deployments.

On App Service you basically have two reliable options:

-Use a custom container (recommended)

Build your own Docker image based on a Python image.

In the Dockerfile, install the SQL Server ODBC driver and unixODBC, e.g. (Ubuntu example):

--RUN apt-get update && \

apt-get install -y curl gnupg && \

curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \

curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list \

  > /etc/apt/sources.list.d/mssql-release.list && \

apt-get update && \

ACCEPT_EULA=Y apt-get install -y msodbcsql18 unixodbc-dev

Deploy this image to App Service. The driver will then always be there.

-Startup script that installs the driver on each start

Add a startup command (e.g. startup.sh) that installs msodbcsql18 before your app starts.

Set it in App Service under Startup Command.

This works, but slows startup and is more fragile than a custom image.

There’s no supported way today to “bake” the ODBC driver into the built-in Python 3.14 stack itself; you need either a custom container or a startup script that installs the driver every time the app starts.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.