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();
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |