C# ODP.Net oracle数据库操作 支持不安装客户端
下载:
http://download.oracle.com/otn/other/ole-oo4o/ODTwithODAC1110720.zip?AuthParam=1414811820_e61f2ffaee346837f680d92d47d75d16
这个是老版本支持.net framework 3.5
下载后,找到以下几个dll,然后放到你的程序exe同一个目录(必须的,不让可能会出莫名错误)下:
* oci.dll (将 'oci.dll.dbl' 改为 'oci.dll'; 位置: ODAC1110710beta.zip \ stage \ Components \ oracle.rdbms.rsf.ic \ 11.1.0.7.0 \ 1 \ DataFiles \ filegroup2.jar)
* Oracle.DataAccess.dll (位置:ODAC1110710beta.zip \ stage \ Components \ oracle.ntoledb.odp_net_2 \ 11.1.0.7.10 \ 1 \ DataFiles \ filegroup4.jar)
* oraociicus11.dll (位置:ODAC1110710beta.zip \ stage \ Components \ oracle.rdbms.ic \ 11.1.0.7.0 \ 1 \ DataFiles \ filegroup3.jar)
* OraOps11w.dll (位置:ODAC1110710beta.zip \ stage \ Components \ oracle.ntoledb.odp_net_2 \ 11.1.0.7.10 \ 1 \ DataFiles \ filegroup3.jar)
下面三个是可选,不过为了能够正常跑起来,最好也一起找出来:
* orannzsbb11.dll (位置: ODAC1110710beta.zip \ stage \ Components \ oracle.ldap.rsf.ic \ 11.1.0.7.0 \ 1 \ DataFiles \ filegroup1.jar)
* oraocci11.dll (位置:ODAC1110710beta.zip \ stage \ Components \ oracle.rdbms.rsf.ic \ 11.1.0.7.0 \ 1 \ DataFiles \ filegroup3.jar)
* ociw32.dll (将'ociw32.dll.dbl' 改为 'ociw32.dll' 位置: ODAC1110710beta.zip \ stage \ Components \ oracle.rdbms.rsf.ic \ 11.1.0.7.0 \ 1 \ DataFiles \ filegroup2.jar)
项目添加引用,并
using Oracle.DataAccess.Client;
连接字符串:
_connecting = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST="+ip+")(PORT="+port+"))" +
"(CONNECT_DATA=(SID=" + dataTable + ")));User Id="+name+";Password="+psw+";";
///获取数据集
private static DataSet GetDataSet(string sql)
{
DataSet ds = new DataSet();
try
{
OpenConnection();
OracleDataAdapter adapter = new OracleDataAdapter(sql, _oracleConnection);
adapter.Fill(ds);
}
catch(Exception ex)
{
}
finally
{
CloseConnection();
}
return ds;
}
如果不出什么幺蛾子,应该没有问题了。
参考:http://www.splinter.com.au/using-the-new-odpnet-to-access-oracle-from-c/
上述方案已知错误:
ORA-12737: Instant Client Light: unsupported server character set %s
解决:应该是字符集不全的问题。从地址 http://download.oracle.com/otn/nt/instantclient/111070/instantclient-basic-win32-11.1.0.7.0.zip?AuthParam=1415600570_939dbedabbec37226193127a354eb4c5 下载 instantclient-basic-win32-11.1.0.7.0.zip (46,734,555 bytes) ,然后找到 oraociei11.dll ,放到 exe同目录下面。 解决非问题。