oracle 在C# 中调用oracle的数据库时,出现引用库和当前客户端不兼容的问题解决方案

网友投稿 1272 2022-11-24

oracle 在C# 中调用oracle的数据库时,出现引用库和当前客户端不兼容的问题解决方案

oracle 在C# 中调用oracle的数据库时,出现引用库和当前客户端不兼容的问题解决方案

oracle 在C# 中调用oracle的数据库时,出现引用库和当前客户端不兼容的问题解决方案

解决方案

1、直接引用  Oracle.ManagedDataAccess.Client.dll动态库即可,

2、引用  Oracle.DataAccess.Client.dll动态库,但根目录下面要有这八个动态库才可以正常使用Oracle 数据库,

(引用 Oracle.DataAccess.Client,但是使用Oracle.DataAccess.dll时,其生成根目录下要有这八个dll(Oracle.ManagedDataAccess这个库相当于后面八个库(oci,ociw32,orannzsbb11,oraocci11,oraociei11,oraons,OraOps11w,OWC11八个动态库))才可以使用11g oracle数据库)

下面是代码

//using Oracle.DataAccess.Client;using Oracle.DataAccess.Client;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;//using System.Data.OracleClient;//using Oracle.ManagedDataAccess.Client;

namespace MyTest{ class Program { static void Main(string[] args) {

#region 引用 Oracle.ManagedDataAccess.Client

//OracleConnection con = null; //try //{ // //string connString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)));User Id=taizhou;Password=taizhou"; // //11g ORACLE // //string connString = "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.144)(PORT = 1521))(CONNECT_DATA = (SID = orcl))); User Id = evms; Password = evms; Pooling = true; Min Pool Size = 10; Max Pool Size = 100; Connection Lifetime = 120; Connection Timeout = 60; Incr Pool Size = 5; Decr Pool Size = 2;"; // //10g ORACLE // string connString = "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.158)(PORT = 1521))(CONNECT_DATA = (SID = ORCL))); User Id = evms; Password = evms; Pooling = true; Min Pool Size = 10; Max Pool Size = 100; Connection Lifetime = 120; Connection Timeout = 60; Incr Pool Size = 5; Decr Pool Size = 2; "; // //string connString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=130.147.246.144)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ECMS)));Persist Security Info=True;User ID=system;Password=Service01;"; // con = new Oracle.ManagedDataAccess.Client.OracleConnection(connString);

// con.Open();

// ////SELECT* FROM TAIZHOU."UserInfo" // //string connstring = @"Data Source=TAIZHOU;User ID=taizhou;Password=taizhou;"; // ////实例化OracleConnection对象 // //OracleConnection conn = new OracleConnection(connstring); // ////打开连接 // //conn.Open();

// StringBuilder stringBuilder = new StringBuilder(); // Oracle.ManagedDataAccess.Client.OracleCommand oracleCommand = new Oracle.ManagedDataAccess.Client.OracleCommand("SELECT * FROM EVMS.USERINFO", con); // var ss = oracleCommand.ExecuteReader(); // while (ss.Read()) // { // string name = ss.GetOracleString(3).ToString(); // stringBuilder.AppendLine(name); // } // Console.WriteLine(stringBuilder.ToString()); // ss.Close(); // Console.Read(); //} //catch (Exception ex) //{ // Console.WriteLine("11111111111111"); //} //finally //{ // con.Close(); //} #endregion

#region 引用 Oracle.DataAccess.Client,但是使用Oracle.DataAccess.dll时,其生成根目录下要有这八个dll(Oracle.ManagedDataAccess这个库相当于后面八个库(oci,ociw32,orannzsbb11,oraocci11,oraociei11,oraons,OraOps11w,OWC11八个动态库))才可以使用11g oracle数据库

OracleConnection con = null; try { //string connString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)));User Id=taizhou;Password=taizhou"; //string connString = "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.144)(PORT = 1521))(CONNECT_DATA = (SID = orcl))); User Id = fcms; Password = fcms; Pooling = true; Min Pool Size = 10; Max Pool Size = 100; Connection Lifetime = 120; Connection Timeout = 60; Incr Pool Size = 5; Decr Pool Size = 2;"; string connString = "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.144)(PORT = 1521))(CONNECT_DATA = (SID = ORCL))); User Id = evms; Password = evms; Pooling = true; Min Pool Size = 10; Max Pool Size = 100; Connection Lifetime = 120; Connection Timeout = 60; Incr Pool Size = 5; Decr Pool Size = 2; "; //string connString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=130.147.246.144)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ECMS)));Persist Security Info=True;User ID=system;Password=Service01;"; con = new OracleConnection(connString);

con.Open();

////SELECT* FROM TAIZHOU."UserInfo" //string connstring = @"Data Source=TAIZHOU;User ID=taizhou;Password=taizhou;"; ////实例化OracleConnection对象 //OracleConnection conn = new OracleConnection(connstring); ////打开连接 //conn.Open();

StringBuilder stringBuilder = new StringBuilder(); OracleCommand oracleCommand = new OracleCommand("SELECT * FROM evms.USERINFO", con); var ss = oracleCommand.ExecuteReader(); while (ss.Read()) { string name = ss.GetOracleString(3).ToString(); stringBuilder.AppendLine(name); } Console.WriteLine(stringBuilder.ToString()); ss.Close(); Console.Read(); } catch (Exception ex) { Console.WriteLine("11111111111111"); } finally { con.Close(); } #endregion } }}

龙腾一族至尊龙骑

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Windows服务启动进程----Cjwdev.WindowsApi.dll
下一篇:HttpWebrequest使用的注意点
相关文章

 发表评论

暂时没有评论,来抢沙发吧~