日期:2014-05-20  浏览次数:20805 次

在.NET2005中怎样连接oracle
我的连接代码如下:但报错

  tempSqlConnection1   =   new   OleDbConnection( "Provider=MSDAORA;DSN=test;User   ID=test;Password=test; ");
  tempSqlConnection1.Open();

test为配好的服务名,用Net   config   assiant   测试通过

{ "ORA-12560:   TNS:   协议适配器错误 "}

------解决方案--------------------
ConnectionString
user id=用户;password=密码;data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=地址)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=服务名)))


using System.Data.OracleClient;
public readonly OracleConnection conn = new OracleConnection(ConnectionString);
conn.Open();

//也可以用Oracle提供的Client
------解决方案--------------------
OracleConnection myConnection=new OracleConnection(ConfigurationSettings.AppSettings[ "OracleConnString "]);

<appSettings>
<add key= "OracleConnString "
value= "user id=lab;data source=oracledb;password=123 "/>
</appSettings>

测试没问题