2685023 - How to connect HANA using Linux ODBC

Symptom

You would like to connect HANA system using ODBC connection in linux application server.

"Image/data in this KBA is from SAP internal systems, sample data, or demo systems. Any resemblance to real data is purely coincidental."

Environment

SAP HANA, platform edition

Resolution

  1. You have to install the unixODBC in your linux server. For how to install the unixODBC, you could have a reference on the Official website : http://www.unixodbc.org/ 
  2. To confirm that your unixODBC is installed, you could using command "odbcinst -j" to check the unixODBC version and Datasource information. 
    ODBCINI.png
    In the later steps, you will need to configure the SYSTEM DATA SOURCES file "/usr/local/etc/odbc.ini".

  3. You have to install HANA client on your linux server. For how to install HANA client, please refer to guide from sap portal : Install the SAP HANA Client on UNIX, macOS, or Linux 
    After the HANA client is installed, go to the directory "/usr/sap/hdbclient" and find the driver "libodbcHDB.so", this means that HANA client is installed successfully. 
    libodbcdriver.png
        
  4. Configure the odbc.ini file "/usr/local/etc/odbc.ini" :
    The format is like below: 
    [<DATABASE_NAME>]
    servernode = <client_ip_address>:<sql_port>
    #location of the unixODBC driver
    driver = /usr/sap/<sid>/HDB<instance_number>/exe/libodbcHDB.so
    description = <optional_description>
    databasename = <your_database_alias>

    My example as below : 
    HSDodbcini.png

  5. Test the ODBC connection by following command:
     "isql <DATABASE_NAME> <user> <password>"
    My example as below: 
    HSTconnectionsuccess.png

  6. In the last test connection, you may get error like the following: 
    # isql HSD <user> <password>
    [ISQL]ERROR: Could not SQLConnect

    In this case, you need to record the strace, using the following command 
    "strace -f -eopen isql <DATABASE_NAME> <user> <password>" 

    In my case, you may get the following information by the strace:
    <hostname>:~ # strace -f -eopen isql HSD <user> <password>
    open("/etc/ld.so.cache", O_RDONLY)      = 3
    open("/usr/local/lib/libodbc.so.2", O_RDONLY) = 3
    open("/usr/lib64/libltdl.so.7", O_RDONLY) = 3
    open("/lib64/libdl.so.2", O_RDONLY)     = 3
    ...
    ...
    open("/root/.hdb/<hostname>/ODBC.shm", O_RDWR) = 3
    open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
    open("/root/.hdb/<hostname>/SSFS_HDB.DAT", O_RDONLY) = 3
    open("/root/.hdb/<hostname>/SSFS_HDB.KEY", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/root/.odbc.ini", O_RDONLY)       = 3
    open("/etc/odbc.ini", O_RDONLY)         = -1 ENOENT (No such file or directory)
    open("/root/.odbc.ini", O_RDONLY)       = 3
    open("/etc/odbc.ini", O_RDONLY)         = -1 ENOENT (No such file or directory)
    [ISQL]ERROR: Could not SQLConnect

     

    This means that the ODBC connection tries to find file "/etc/odbc.ini", but this does not exist. Actually, it is the file "/usr/local/etc/odbc.ini" where we maintained the ODBC connection. So you need to create a soft link to this file. 
    ln -s /usr/local/etc/odbc.ini /etc/odbc.ini

    After the symbolic link is created. this error will disappear. And the connection test will succeed.

Keywords

unixODBC, SUSE, ODBC Driver, odbc.ini, windows

posted on 2024-11-18 16:36  BASIS/老应  阅读(50)  评论(0)    收藏  举报

导航