Friday, February 26, 2016

MapR Drill ODBC fails to connect with error "Unable to locate SQLGetPrivateProfileString function"

Symptom:

MapR Drill ODBC fails to connect with error "Unable to locate SQLGetPrivateProfileString function".
One example is when using "iodbctest" command, it fails to connect:
iodbctest
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.0709.0909

Enter ODBC connect string (? shows list): ?

DSN                              | Driver
------------------------------------------------------------------------------
Sample MapR Drill DSN 64         | MapR Drill ODBC Driver 64-bit

Enter ODBC connect string (? shows list): DSN=Sample MapR Drill DSN 64
1: SQLDriverConnect = [MapR][ODBC] (11560) Unable to locate SQLGetPrivateProfileString function. (11560) SQLSTATE=HY000
1: ODBC_Connect = [MapR][ODBC] (11560) Unable to locate SQLGetPrivateProfileString function. (11560) SQLSTATE=HY000

Env:

Drill 1.4
MapRDrillODBC-1.2.1
libiodbc-3.52.7

Root Cause:

This issue normally happens if we made mistakes in the "Step 4: Configure the MapR Drill ODBC Driver" in https://drill.apache.org/docs/configuring-odbc-on-linux/
For example, by default, .mapr.drillodbc.ini assumes the driver manager is iODBC and its library is libiodbcinst.so.
# Generic ODBCInstLib
#   iODBC
ODBCInstLib=libiodbcinst.so
However if that "libiodbcinst.so" does not exist in LD_LIBRARY_PATH, then above error will show up.

Solution:

1. Identify which driver manger is installed.

2. Locate the ODBCInstLib file for that driver manager.

Take iODBC 3.52.7 on CentOS6 for example:
# rpm -qa|grep -i iodbc
libiodbc-3.52.7-1.el6.x86_64
Then locate its ODBCInstLib file:
# rpm -ql libiodbc|grep libiodbcinst
/usr/lib64/libiodbcinst.so.2
/usr/lib64/libiodbcinst.so.2.1.19
Actually here /usr/lib64/libiodbcinst.so.2 is a softlink to /usr/lib64/libiodbcinst.so.2.1.19
# ls -altr /usr/lib64/libiodbcinst.so.2
lrwxrwxrwx 1 root root 22 Feb 26 11:45 /usr/lib64/libiodbcinst.so.2 -> libiodbcinst.so.2.1.19
So we know that /usr/lib64/libiodbcinst.so.2 is what we want.

3. Put correct ODBCInstLib file in .mapr.drillodbc.ini

In above example, we should change default "libiodbcinst.so" to "libiodbcinst.so.2":
# Generic ODBCInstLib
#   iODBC
ODBCInstLib=libiodbcinst.so.2

4. Add the path to ODBCInstLib in LD_LIBRARY_PATH

In above example, we should add "/usr/lib64" into existing LD_LIBRARY_PATH:
# cat .bashrc|grep LD_LIB
export LD_LIBRARY_PATH=/usr/local/lib:/opt/mapr/drillodbc/lib/64:/usr/lib64/

5. Test to connect again

# iodbctest
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.0709.0909

Enter ODBC connect string (? shows list): ?

DSN                              | Driver
------------------------------------------------------------------------------
Sample MapR Drill DSN 64         | MapR Drill ODBC Driver 64-bit

Enter ODBC connect string (? shows list): DSN=Sample MapR Drill DSN 64
Driver: 1.2.1.1001 (MapR Drill ODBC Driver)

SQL>


No comments:

Post a Comment

Popular Posts