msphpsql: 1617 SQLSTATE [IM004, 0]: [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
Hi I am running the new drivers under php:fpm on docker with the following Dockerfile
FROM php:fpm
MAINTAINER Diego Gullo <diego_gullo@bizmate.biz>
# Add Microsoft repo for Microsoft ODBC Driver 13 for Linux
RUN apt-get update && apt-get install -y \
apt-transport-https \
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update
# Install Dependencies
RUN ACCEPT_EULA=Y apt-get install -y \
unixodbc \
unixodbc-dev \
libgss3 \
odbcinst \
msodbcsql \
locales \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
# Install pdo_sqlsrv and sqlsrv from PECL. Replace pdo_sqlsrv-4.1.8preview with preferred version.
RUN pecl install pdo_sqlsrv-4.1.9preview sqlsrv-4.1.9preview \
&& docker-php-ext-enable pdo_sqlsrv sqlsrv
RUN apt-get install -y libpq-dev libcurl4-gnutls-dev \
&& docker-php-ext-install curl pdo pdo_pgsql
When running a query I get the error
1617 SQLSTATE [IM004, 0]: [unixODBC][Driver Manager]Driver’s SQLAllocHandle on SQL_HANDLE_HENV failed
I am using the preview version 9 because the stable packages wont work and give this error when running a build
ERROR: `make' failed
error: /usr/local/lib/php/extensions/no-debug-non-zts-20160303/pdo_sqlsrv does not exist
A full log provided in the file pecl_install_sqlsrv_Fails.txt
Any suggestions on how to fix the problem is appreciated
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (10 by maintainers)
This seems to occur when the UID of the process using the ODBC driver is not in /etc/passwd. A simple fix is to create a user having that UID.
This could explain why running as root solves this issue, as UID 0 is always present.
We experienced this issue when using running
pyodbc.connect("DRIVER={ODBC Driver 17 for SQL Server},...)from inside a Docker container started by Jenkins using the UID of the jenkins user of the host. This UID had no corresponding user inside our container.My dockerized PHP errored out with “Driver’s SQLAllocHandle on SQL_HANDLE_HENV failed” if not executed as root, too. Solution was to map host’s /etc/passwd and /etc/group into the container. Using docker-compose.yml:
@bizmate Aha! I can now reproduce your error. The reason I could not reproduce it earlier is because I was calling
sudo make up. However now I have added my local user to the docker group and now I get the same error message you do. I will continue to investigate.Thanks @jakjohnson. Hope the others find this helpful.