服务器oracle版本是11g,
客户端装了11g后常出问题,使用 Oracle.DataAccess.Client的时候提示oraops12.dll无法加载,使用system.data.oracleclient时,提示需要8.1.7的客户端
下载安装了12g的客户端后正常。
下载地址:http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html
下载的是: ODTwithODAC121024.zip 304 MB (319,813,071 bytes)
安装后,环境变量path中自动加入了客户端路径
修改客户端路径下的tnsnames.ora文件内容,如下:
服务名字sid =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.100)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
)
)
plsql工具->首选项->oracle->连接,设置oracle主目录名,oci库地址,退出再登陆,就可连接到数据库。
web.config
<configSections>
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<connectionStrings>
<add name="DataCenter" connectionString="DATA SOURCE=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.100)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)));PASSWORD=****;USER ID=****" providerName="Oracle.ManagedDataAccess.Client" />
</connectionStrings>
项目中加入引用:F:\app\client\ly\product\12.1.0\client_1\odp.net\bin\4\Oracle.DataAccess.dll
代码(这里使用了dapper):
using (OracleConnection conn = DapperFactory.CrateOracleConnection())
{
string executeSql = @" INSERT INTO RIGHTS (NAME, FARTHERID, ICON, ORDERNUMBER, URL, TYPE )
VALUES (:NAME, :FARTHERID, :ICON, :ORDERNUMBER, :URL, :TYPE) ";
return conn.Execute(executeSql, r) > 0 ? true : false;
}