Skip to Content

How To connect to SAP Hana using Net Framework.

Example in C#. You can also connect the same way in VB.net or any other .net language like delphi.net.

1. the odbc driver to use in 64 bit have a different name than on 32 bit.

2. with this method, you do not use to create an odbc on the windows system.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Data.Odbc;

namespace HanaODBCConnection

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            // hana server : port. Port is 3XX15 where XX is the instance number

 

            const string _strServerName = "hanaServer:30015";

            const string _strLoginName = "SYSTEM";

            const string _strPassword = "Password";

            string strConnectionString = string.Empty;

            //Does NOT require to create an odbc connection in windows system

 

            if( IntPtr.Size == 8 ){

               // Do 64-bit stuff

                strConnectionString = string.Concat(strConnectionString, "Driver={HDBODBC};");

            }else{

               // Do 32-bit

               strConnectionString = string.Concat(strConnectionString, "Driver={HDBODBC32};");

            }

            strConnectionString = string.Concat(strConnectionString, "ServerNode=", _strServerName, ";");

            strConnectionString = string.Concat(strConnectionString, "UID=", _strLoginName, ";");

            strConnectionString = string.Concat(strConnectionString, "PWD=", _strPassword, ";");

 

            OdbcConnection hanaConn = new OdbcConnection(strConnectionString.ToString());

            try

            {

                hanaConn.Open();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.ToString());

            }

            finally

            {

                hanaConn.Dispose();

            }

        }

    }

}

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply