Driver's SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect) when connecting to Azure SQL database from Python running in OpenShift Driver's SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect) when connecting to Azure SQL database from Python running in OpenShift python-3.x python-3.x

Driver's SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect) when connecting to Azure SQL database from Python running in OpenShift


unixODBC is trying to find the odbc.ini in the current users home directory. It's trying to do this by looking up the user in /etc/passwd. Since Openshift is using a project specific UID which does not exist in /etc/passwd the user lookup will not work and the connection will fail.

To resolve this add the following to the dockerfile

ADD entrypoint.sh .RUN chmod 766 /etc/passwd....ENTRYPOINT entrypoint.sh

And the following in the entrypoint script

export $(id)echo "default:x:$uid:0:user for openshift:/tmp:/bin/bash" >> /etc/passwdpython3.7 app.py

The above will insert the current user to /etc/passwd during startup of the container.

An alternative and probably better approach might be to use nss_wrapper:https://cwrap.org/nss_wrapper.html


I encountered the same problem while using django on Windows.After upgrading the 'SQL Server 2017 client' to the latest client resolves my issue.Use below link to download latest patch:https://www.microsoft.com/en-us/download/details.aspx?id=56567