Skip to Content
Author's profile photo Ethan Zhang

HANA with odbc on Ubuntu 12.04


Recently I’m kinda of fancy with Nodejs, but as you know that nodejs doesn’t support many RDBMS. I know node can connect to MySQL and mongoDB but definitely not HANA, since no one write a drive base on hana database. I’m not an expert of HANA and even Nodejs, so write a drive of HANA is beyond my knowledge. So I decide to connect HANA on my Ubuntu through odbc

But I encountered lots of problems when I was trying to accomplish the job that I think it’s simple enough, but actually it take me four hours to figure it out how to. I decided to document it just in case someone else need to configure HANA with odbc and maybe it can save you times.

1.Install HANA Client on Linux

My environment is Ubuntu 12.04, connect HANA via Windows is easy and well documented. I highly recommend you to install HANA client on your Ubuntu, because you test and debug your connection with HANA. I wrote another post and share you how to install it. My installation is under /opt/sap/hdbclient, if the HANA client was successfully installed. execute command ./hdbsql under /opt/sap/hdbclient you will get

ethanz@ubuntu:/opt/sap/hdbclient$ ./hdbsql

Welcome to the SAP HANA Database interactive terminal.

Type:  \h for help with commands         

       \q to quit                        


You can test your connection first by typing following command, now I’m connecting to our modeling server which is a testing environment.

hdbsql=> \c -n your-hana-server -u username -p secret

Connected to VS5@xml1009:30015

hdbsql VS5=>

2, Install unixodbc and odbcinst on Ubuntu

Before you connect to HANA via odbc, first make sure the odbc and odbc client was installed. odbcinst is the command tool to manage your DSN entry. unixodbc is used to  connect actual database.

Install odbc and odbcinst by following command

sudo apt-get install unixodbc unixodbc-dev

sudo apt-get install odbcinst

3,Edit your ODBC Entry

After successfully install unixodbc, system will create two blank ini files /etc/odbc.ini and /etc/odbcinst.ini. Go ahead edit /etc/odbc.ini with your favorite text editor and the input like followings:


Driver              = /opt/sap/hdbclient/

ServerNode      =hana-server-name:30015

I don’t know why the configuration is totally different with others (like MySQL). Be careful with the key of ServerNode. It’s not Host or Server, the key is ServerNode, otherwise odbc will try to connect to your localhost and always get connection errors. And I found the username and password in the odbc.ini file does NOT work, so you don’t need them at all.

4, Test your connection

After step 3, you are almost done, now let’s test your connection and how does it work. In your terminal, type

isql hana username password

If you see following responses, congratulations

ethanz@ubuntu:~$ isql hana username password


| Connected!                            |

|                                       |

| sql-statement                         |

| help [tablename]                      |

| quit                                  |

|                                       |



5, Connect hana via Python with odbc.

Write a simple test script and see how it’s work

import pyodbc

conn = pyodbc.connect(‘DSN=hana;UID=username;PWD=password’)

print conn

If there’s no exception throw out and you can see the connection print out, congrats.

<pyodbc.Connection object at 0x155fd98>

6, Conclusion

Several things need wrap up, one thing is the configuration key, it’s ServerNode instead of Host/Server. another thing is you have to implicitly to provide the username and password in your connection string or terminal isql command.

Last thing to remember, if you install pyodbc via pip like sudo pip install pyodbc, make sure you have installed python-dev, otherwise the compilation will fail.

sudo apt-get install python-dev && sudo pip install pyodbc

Ok, fellows, that’s it. Good luck with your HANA journey.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Thank you for the nice post! However, the same thing can achieved on a Windows client by installing pyodbc from:

      Recently, I wrote a blog about this here, thanks to Ethan's contribution:

      Author's profile photo Kristian Rink
      Kristian Rink

      All along the lines I wrote an article similar to this, but focussing on SAP MaxDB rather than HANA (as we use MaxDB outside the SAP world). See for more on that. I'll however keep reading through your posts, they seem rather inspiring. 🙂

      Author's profile photo Denys van Kempen
      Denys van Kempen

      Commenting here for those that are still reading your post as a result of a Google search.

      Just uploaded a video to the SAP HANA SPS 08 installation playlist that addresses ODBC:

      BTW: For SPS 08, according to the product availability matrix, supported Linux platforms are SLES and RHEL, not Ubuntu. This may change in the future so first check

      Since SPS 02, ODBC also has been documented in the SAP HANA developer guide (chapter 13).

      Denys van Kempen, SAP HANA Academy

      Author's profile photo Former Member
      Former Member

      When i try to connect using command line then connection successfull.

      But when i try to connect using php then no dataset retrun and not error.

      Author's profile photo Former Member
      Former Member

      Thanks! Works nicely on Ubuntu 14.04 with a Rev91 HANA client.

      Author's profile photo Patrice VIGIER
      Patrice VIGIER


      This works for Debian server.

      I have seen in the SAP video that driver unixodbc 2.3 must be installed, but I confirm that it work with version 2.2



      Author's profile photo Former Member
      Former Member


      To have dynamic connection, without updating odbc.ini, you have to declare driver in file /etc/odbcinst.ini

      $ cat /etc/odbcinst.ini

      Then, you can connect using PDO or odbc_connect using this declared driver (called hanadriver)

      $DSN="hana;DRIVER={hanadriver};ServerNode=" . $host . ":" . $conn_port;
      $conn = odbc_connect($DSN, "USERNAME", "PASSWORD", SQL_CUR_USE_ODBC);
          if (!($conn)) {
              echo "<p>Connection to DB via ODBC failed: ";
              echo odbc_errormsg($conn);
              echo "</p>\n";
          } else {
              $sql = "SELECT * FROM SYS.M_DISK_USAGE";
              $rs = odbc_exec($conn, $sql);
              while ($row = odbc_fetch_object($rs)) {


      Same example with PDO

      $odbc_string = "DRIVER={hanadriver};ServerNode=" 
      . $hana_params['host'] . ":" 
      . $hana_params['db_conn_port'] . ";DATABASE=" 
      . $hana_params['db_conn_database']
      . ";Uid=" . $hana_params['db_conn_username'] 
      . ";Pwd=" . $hana_params['db_conn_password'] . ";";
          try {
              $pdo = new PDO("odbc:$odbc_string");
          } catch (Exception $e) {
              print $msg = "EXCEPTION at logon Catched : " . $e->getMessage();
              $code_retour = 99;
          $msg=$pdo->prepare("SELECT * FROM SYS.M_DISK_USAGE");
          while ($row = $msg->fetchObject()) {
      Author's profile photo Patrice VIGIER
      Patrice VIGIER


      This works also for Debian 9 server with driver unixodbc 2.3.4-1.