SAP

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Connect Using the SAP HANA ODBC Driver

Connect to SAP HANA using an ODBC data source.

Overview

You will learn

  • ✔How to create and test an SAP HANA ODBC data source
  • ✔How to use an ODBC data source in an application

More from Dan van Leeuwen

See all 60 tutorials by Dan van Leeuwen →

Prerequisites

  • You have completed the first 3 tutorials in this mission.

Steps

Platform: Windows macOS Linux

Intro

Open Database Connectivity (ODBC) provides an API for accessing databases. Database vendors provide ODBC drivers for their database products. An application written to the ODBC standard can be ported to other databases that also provide an ODBC interface.


Step 1 Configure a data source
—

The ODBC Data Source Administrator lists the installed ODBC drivers and the configured data sources.

  1. Open the administrator by entering ODBC after clicking on the Microsoft Windows start icon.

    Ensure that you choose the 64-bit version if you have the 64-bit version of the SAP HANA client installed.

    Start the ODBC Administrator
    Start the ODBC Administrator

  2. Click the Drivers tab and view the installed drivers.

    odbc admin drivers
    odbc admin drivers

    The SAP HANA ODBC driver (HDBODBC) is visible.

  3. Click the User DSN tab to view the data sources.

  4. Click Add to create a new data source to connect to a SAP HANA database.

    Add ODBC user data source
    Add ODBC user data source

  5. Select HDBODBC and click Finish.

    New data source
    New data source

  6. Example data source configuration for SAP HANA Cloud.

    For the host, paste the SQL Endpoint from your instance. For more details, review Choose an SAP HANA Database.

    ODBC HANA Cloud
    ODBC HANA Cloud

  7. Example data source configuration for SAP HANA on-premise instance.

    ODBC HXE
    ODBC HXE

    To connect to SAP HANA on-premise, Multitenant should be checked and the Validate TLS/SSL certificate option can be unchecked. For more information on this topic, see How to Configure TLS/SSL in SAP HANA 2.0.

  8. Click Test connection.

    Test Succeeded
    Test Succeeded

    The user name USER1 and password Password1 can be entered when prompted for credentials.

  9. Press OK to save the data source.

    Saved values can also be viewed using the Microsoft Windows registry editor under the key Computer\HKEY_CURRENT_USER\Software\ODBC\ODBC.INI.

For additional details see Connect to SAP HANA via ODBC.

The following instructions demonstrate how unixODBC can be used to configure and test a data source on Linux or Mac.

  1. On SUSE Linux, the YaST installer can be used to install unixODBC.

    YaST installer
    YaST installer

    For more details on how to accomplish this, please follow the second step of this tutorial.

  2. On a Mac, unixODBC can be installed using Homebrew.

    Shell
    brew install unixodbc
  3. The following commands can be used to confirm that unixODBC is installed, determine the location of the .odbc.ini file (if it exists), and to confirm the location of the SAP HANA client install that contains the ODBC driver.

    Shell
    odbcinst -j
    which hdbsql

    odbcinst
    odbcinst

  4. Navigate to a directory, similar to the first one that is highlighted in the screenshot above.

    Shell
    cd $HOME
  5. Edit the .odbc.ini file (or create it if it does not exist) to add one or more data sources. Be sure to configure the values of servernode and driver so that they conform with your setup.

    The driver’s file extension is dylib instead of so on a Mac.

    .odbc.ini
    [HANA_Cloud]
    servernode = 6b7ae0da-ee5a-4782-bc7e-297099099b59.hana.prod-ca10.hanacloud.ondemand.com:443
    driver = /home/dan/sap/hdbclient/libodbcHDB.so
    encrypt = true
    sslValidateCertificate = true
    sessionVariable:APPLICATION = ODBC Application
    
    [HANA_OnPremise]
    servernode = hxehost:39015
    driver = /home/dan/sap/hdbclient/libodbcHDB.so
    databasename = HXE
    sessionVariable:APPLICATION = ODBC Application

    The sessionVariable:APPLICATION property sets a custom application name for the connection. This value can be viewed in the CLIENT_APPLICATION column of the M_CONNECTIONS system view and may also appear in SAP HANA telemetry data.

  6. unixODBC provides a basic SQL query tool called isql that can be used to validate a data source.

    Shell
    isql -v HANA_Cloud User1 Password1

    Once you see a message that indicates a connection has been made, enter the following statement to verify this.

    Shell
    SELECT * FROM HOTELS.CUSTOMER

    isql
    isql

The following instructions demonstrate how unixODBC can be used to configure and test a data source on Linux or Mac.

  1. On SUSE Linux, the YaST installer can be used to install unixODBC.

    YaST installer
    YaST installer

    For more details on how to accomplish this, please follow the second step of this tutorial.

  2. On a Mac, unixODBC can be installed using Homebrew.

    Shell
    brew install unixodbc
  3. The following commands can be used to confirm that unixODBC is installed, determine the location of the .odbc.ini file (if it exists), and to confirm the location of the SAP HANA client install that contains the ODBC driver.

    Shell
    odbcinst -j
    which hdbsql

    odbcinst
    odbcinst

  4. Navigate to a directory, similar to the first one that is highlighted in the screenshot above.

    Shell
    cd $HOME
  5. Edit the .odbc.ini file (or create it if it does not exist) to add one or more data sources. Be sure to configure the values of servernode and driver so that they conform with your setup.

    The driver’s file extension is dylib instead of so on a Mac.

    .odbc.ini
    [HANA_Cloud]
    servernode = 6b7ae0da-ee5a-4782-bc7e-297099099b59.hana.prod-ca10.hanacloud.ondemand.com:443
    driver = /home/dan/sap/hdbclient/libodbcHDB.so
    encrypt = true
    sslValidateCertificate = true
    sessionVariable:APPLICATION = ODBC Application
    
    [HANA_OnPremise]
    servernode = hxehost:39015
    driver = /home/dan/sap/hdbclient/libodbcHDB.so
    databasename = HXE
    sessionVariable:APPLICATION = ODBC Application

    The sessionVariable:APPLICATION property sets a custom application name for the connection. This value can be viewed in the CLIENT_APPLICATION column of the M_CONNECTIONS system view and may also appear in SAP HANA telemetry data.

  6. unixODBC provides a basic SQL query tool called isql that can be used to validate a data source.

    Shell
    isql -v HANA_Cloud User1 Password1

    Once you see a message that indicates a connection has been made, enter the following statement to verify this.

    Shell
    SELECT * FROM HOTELS.CUSTOMER

    isql
    isql

Step 2 Set custom application name
+
Step 3 Use a SAP HANA data source from another program
+
Step 4 Knowledge check
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 4
1. Configure a data source 2. Set custom application name 3. Use a SAP HANA data source from another program 4. Knowledge check
Next