C# Oracle代理连接,免安装客户端
需要.net4平台,引用之后,访问工具类示例: using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Security.Cryptography; using System.IO; using Oracle.ManagedDataAccess.Client; namespace DBconnection { public class DBHelper { /// /// 读取数据库 连接 /// public static readonly string OracleConnectionStr = @"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.9.211)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=HIS)));Persist Security Info=True;User ID=ZLHIS;Password=o15ntu;"; /// /// 集合查询:在此完成所有的集合类型查询 /// /// 查询语句 /// 结果集合 public static DataSet OracleFillTable(string sqlQuery) { using (OracleConnection con = new OracleConnection(OracleConnectionStr)) { //创建数据适配器,将查询语句及连接字符串两个参数传进数据适配器 con.Open(); OracleCommand cmd = con.CreateCommand(); cmd.CommandText = sqlQuery; //新建一个表格对象dt,用来获取查询的数据 DataSet ds = new DataSet(); try { //填充表格 OracleDataAdapter oda = new OracleDataAdapter(cmd); oda.Fill(ds); //如果查询无误,则返回查询出的数据 return ds; } catch { //执行查询出现错误,返回null值 return null; } finally { //主动销毁所用的资源 ds.Dispose(); cmd.Dispose(); // 关闭连接 con.Close(); } } } /// /// 集合查询:在此完成所有的集合类型查询 /// /// 查询语句 /// 结果集合 public static string OracleGetTable(string sqlQuery) { string result = null; try { using (OracleConnection con = new OracleConnection(OracleConnectionStr)) { OracleCommand cmd = con.CreateCommand(); try { con.Open(); cmd.CommandText = sqlQuery; try { //执行sql语句 result = cmd.ExecuteScalar().ToString(); } catch { result = "-1"; } } catch (Exception e) { throw new Exception("数据库连接出现错误!"); } finally { //主动销毁资源 cmd.Dispose(); // 关闭连接 con.Close(); } } } catch (Exception e) { // MessageBox.Show(e.ToString()); } return result; } } } 连接 /// public static readonly string OracleConnectionStr = @"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.9.211)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=HIS)));Persist Security Info=True;User ID=ZLHIS;Password=o15ntu;"; /// /// 集合查询:在此完成所有的集合类型查询 /// /// 查询语句 /// 结果集合 public static DataSet OracleFillTable(string sqlQuery) { using (OracleConnection con = new OracleConnection(OracleConnectionStr)) { //创建数据适配器,将查询语句及连接字符串两个参数传进数据适配器 con.Open(); OracleCommand cmd = con.CreateCommand(); cmd.CommandText = sqlQuery; //新建一个表格对象dt,用来获取查询的数据 DataSet ds = new DataSet(); try { //填充表格 OracleDataAdapter oda = new OracleDataAdapter(cmd); oda.Fill(ds); //如果查询无误,则返回查询出的数据 return ds; } catch { //执行查询出现错误,返回null值 return null; } finally { //主动销毁所用的资源 ds.Dispose(); cmd.Dispose(); // 关闭连接 con.Close(); } } } /// /// 集合查询:在此完成所有的集合类型查询 /// /// 查询语句 /// 结果集合 public static string OracleGetTable(string sqlQuery) { string result = null; try { using (OracleConnection con = new OracleConnection(OracleConnectionStr)) { OracleCommand cmd = con.CreateCommand(); try { con.Open(); cmd.CommandText = sqlQuery; try { //执行sql语句 result = cmd.ExecuteScalar().ToString(); } catch { result = "-1"; } } catch (Exception e) { throw new Exception("数据库连接出现错误!"); } finally { //主动销毁资源 cmd.Dispose(); // 关闭连接 con.Close(); } } } catch (Exception e) { // MessageBox.Show(e.ToString()); } return result; } } }