Skip to Content
Author's profile photo Former Member

Connecting to SAP HANA through Python in windows 7

I am a part of Product Security APJ team which is developing a tool that uses MySQL as a database. Few days back we decided to move data from MySQL to SAP HANA due to performance issues. Due to this one of the major challenge that we faced was in making connection to SAP HANA through Python. It was hard to find discussions related to this problem which led to referring multiple HANA docs. Once we came up with a solution, we thought of consolidating the solution and make it available for others.

Here is a detailed explanation about how to connect to SAP HANA using Python in Windows 7.

Installing HANA client on Windows:

  1. Go to the folder where the DUMP (build of HANA client) is available using command prompt

   2.  Write the following command.

  • hdbinst -a client

Screenshot of the installation is shown below :

Capture.PNG

  3. Restart the windows system.

Connecting to the HANA DB through python:


To make DSN less connection:


  1. Once the HANA client is successfully installed , download and run the module : Pyodbc-3.0.6.win-amd64-py2.7.exe

   2.  To connect to the HANA DB through python use the below statement  in your code:

         Capture10.PNG

    where,

  1. self.driver is  name of the HANA driver installed (HDBODBC)
  2. self.server is  path or location where the HANA DB resides. (Eg: inblrlxxx.dhcp.blrl.sap.corp:300XX)
  3. self.UID is the username for a particular database you want to connect.
  4. self.PWD is the password for a particular database you want to connect.

To make DSN connection:


  1. Open Data Source(ODBC) in windows, select System DSN and click on “Add button”.

   2.  It will ask for you to select a driver name from the list available. Select HDBODBC.

   3.  Then enter the details. Server:port should be the path or location where the HANA DB resides.

                    Capture1.PNG              

   4.  Click “Connect” to test the connection. Provide Username and password for the database you want to connect.

   5.  On successful connection, make use of the below code to make DSN connection through python:

           Capture11.PNG

    where,

  1. self.DSN is the name of the Data Source Name you provided in ODBC connection.
  2. self.UID is the username for the particular database you want to connect.
  3. self.PWD is the password for the particular database you want to connect.

Similarly to connect to SAP HANA through PHP in Windows 7, explanation is provide in my other post: Connecting to SAP HANA through PHP in windows 7

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.