While connecting to SQL from client application(running on linux server), using using ‘SQL Native client 11.0 (ODBC) driver for Linux’ we were getting following error message.
[root@axxxxxazureapi]# isql -v< DSN> <USERNAME> <PASSWORD>
[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
[ISQL]ERROR: Could not SQLConnect
In my case the issue is related with wrong installation path of the sqlncli dll. when we were trying to connect to SQL from Linux the application is trying to get the dll from a different path.
odbcinst –j from linux command prompt and verified that unixODBC 2.3.0 (exactly that version, not older or newer) is installed.
Output is following:
$ odbcinst -j
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/odbcuser/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
How to get the ODBC trace:
The ODBC Driver for SQL Server on Linux supports tracing of ODBC API call entry and exit.
To trace your application behavior, first add the following line to the odbcinst.ini file:
Then start your application with strace. For example:
strace -t -f -o trace_out.txt executable
In place of executable just use the command that you are using to run your application. In our case it is like following.
strace -t -f -o trace_out.txt isql -v <DSN>< USERNAME> <PASSWORD>
Once you get the error check the trace file. It will give you more information about the connection failure. On that basis you can troubleshoot the issue.
In my case the path of sqlncli.dll is not found because the application is pointing to a different path and the sqlncli.dll was installed to a different location. After moving the file to that location our application was working fine.
Author : Mukesh(MSFT), Suport engineer, Microsoft
Reviewed by : Snehadeep(MSFT), SQL Developer Technical Lead, Microsoft