Create an ODBC database connection for Hana.
Default in Control Panel--"Administrative Tools--" data source (ODBC)
Tip: If the system is 64-bit, configure it to run the 32-bit ODBC in C:\Windows\SysWOW64\odbcad32.exe.
After you have configured ODBC, use: OdbcConnection connection in C # projects
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/// <summary> /// 根据SQL语句查询数据 /// </summary> /// <param name="sql">SQL查询语句</param> /// <returns>结果集</returns> public DataSet getDataSetBySql(String sql) { try { DataSet ds = new DataSet(); OdbcCommand command = new OdbcCommand(sql); //command 对象 String connstring = "dsn=ODBCNAME;uid=USERID;pwd=PASSWORD"; //ODBC连接字符串 using (OdbcConnection connection = new OdbcConnection(connstring)) //创建connection连接对象 { command.Connection = connection; connection.Open(); //打开链接 OdbcDataAdapter adapter=new OdbcDataAdapter(command); //实例化dataadapter adapter.Fill(ds); //填充查询结果 return ds; } } catch (Exception ex) { throw new Exception(ex.Message); } } |