Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Error: ('IM004', "[IM004] [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect)") #2

Open
jakedubb opened this issue Jan 2, 2019 · 2 comments
Labels
help wanted Extra attention is needed research

Comments

@jakedubb
Copy link

jakedubb commented Jan 2, 2019

Getting this error when attempting to use pyodbc in my django application. When I ssh into the container I am able to use sqlcmd to execute queries using the same connection string as my app is using. I've seen that this might be a permissions issue however I have configured everything to run as root and am still seeing this issue.

Stack Trace:

Error: ('IM004', "[IM004] [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect)")
File "django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "sql_server/pyodbc/base.py", line 303, in get_new_connection
timeout=timeout)
Error: ('IM004', "[IM004] [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect)")
File "django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "app/views.py", line 40, in app_index
dom = DomainNames.availabledoms.random()
File "app/models.py", line 81, in random
count = self.aggregate(count=Count('id'))['count']
File "django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "django/db/models/query.py", line 356, in aggregate
return query.get_aggregation(self.db, kwargs.keys())
File "django/db/models/sql/query.py", line 457, in get_aggregation
result = compiler.execute_sql(SINGLE)
File "django/db/models/sql/compiler.py", line 824, in execute_sql
sql, params = self.as_sql()
File "sql_server/pyodbc/compiler.py", line 73, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "django/db/models/sql/compiler.py", line 46, in pre_sql_setup
self.setup_query()
File "django/db/models/sql/compiler.py", line 37, in setup_query
self.select, self.klass_info, self.annotation_col_map = self.get_select()
File "django/db/models/sql/compiler.py", line 226, in get_select
ret.append((col, self.compile(col, select_format=True), alias))
File "sql_server/pyodbc/compiler.py", line 213, in compile
return super(SQLCompiler, self).compile(node, select_format)
File "django/db/models/sql/compiler.py", line 351, in compile
sql, params = vendor_impl(self, self.connection)
File "sql_server/pyodbc/compiler.py", line 23, in _as_sql_count
return self.as_sql(compiler, connection, function='COUNT_BIG')
File "django/db/models/expressions.py", line 517, in as_sql
connection.ops.check_expression_support(self)
File "sql_server/pyodbc/operations.py", line 78, in check_expression_support
if self.connection.sql_server_version < 2008:
File "django/utils/functional.py", line 35, in get
res = instance.dict[self.name] = self.func(instance)
File "sql_server/pyodbc/base.py", line 390, in sql_server_version
with self.temporary_connection() as cursor:
File "python3.6/contextlib.py", line 81, in enter
return next(self.gen)
File "django/db/backends/base/base.py", line 564, in temporary_connection
cursor = self.cursor()
File "django/db/backends/base/base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "django/db/backends/base/base.py", line 204, in _cursor
self.ensure_connection()
File "django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "django/db/utils.py", line 94, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "sql_server/pyodbc/base.py", line 303, in get_new_connection
timeout=timeout)

@robertpeteuil
Copy link
Collaborator

robertpeteuil commented Jan 10, 2019

Thanks for the heads up on this.

Based on a search of the error, it certainly appears to be some sort of permission error. The MS driver was difficult to get working in a container, so I suspect they may have changed something that requires another tweak.

@robertpeteuil robertpeteuil added help wanted Extra attention is needed research and removed research labels Apr 14, 2019
@docktermj
Copy link

Related issue: microsoft/mssql-docker#431

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed research
Development

No branches or pull requests

3 participants