使用的DLL:Oracle.ManagedDataAccess

Bug:OracleInternal.Common.ProviderConfig的类型初始值设定项引发异常

App.config的更改才是关键

关键应该是这个:

  oracle.manageddataaccess默认情况下只支持direct connection,
  如果要支持tns name,即ez connection,需要在app.config或者web.config里添加如下设置

安装后的App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</configSections>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client"/>
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no"/>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
<bindingRedirect oldVersion="4.122.0.0 - 4.65535.65535.65535" newVersion="4.122.18.3"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) "/>
</dataSources>
</version>
</oracle.manageddataaccess.client>
</configuration>

更改后的App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client"/>
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no"/>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
<bindingRedirect oldVersion="4.122.0.0 - 4.65535.65535.65535" newVersion="4.122.18.3"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

去掉的节点 如下:

<configSections>
<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</configSections>
  <oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) "/>
</dataSources>
</version>
</oracle.manageddataaccess.client> 

代码:

OracleHelper

 public class OracleHelper1
{
public static OracleCommand cmd = null;
public static OracleConnection conn = null;
public static string connstr = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.2.98)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=JJJT)));User Id=CMSP;Password=Oracle1"; public static OracleConnection init()
{
try
{
conn = new OracleConnection(connstr);
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
}
catch (Exception e)
{
throw new Exception(e.Message.ToString());
}
return conn;
} public static DataSet GetDataSet(string sqlstr)
{
DataSet set = new DataSet();
try
{
init();
OracleDataAdapter adp = new OracleDataAdapter(sqlstr, conn);
adp.Fill(set);
conn.Close();
}
catch (Exception e)
{
throw new Exception(e.Message.ToString());
}
return set;
} public static int ExecuteNonQuery(string cmdText)
{
int count;
try
{
init();
cmd = new OracleCommand(cmdText, conn);
count = cmd.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
return count;
}
}

CS代码

DataTable dt1 = OracleHelper1.GetDataSet("select * from TB_PROJECTS").Tables[];

Oracle 连接数据库的更多相关文章

  1. oracle连接数据库报错:ORA-01034: ORACLE not available(Oracle 不存在),ORA-27101: shared memory realm does not exist

    花一天半的时间解决客户端连接服务端的oracle数据库,无法连接问题.ORA-01034: ORACLE not available(Oracle 不存在),ORA-27101: shared mem ...

  2. Oracle连接数据库的封装类OracleDB

    import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.S ...

  3. oracle连接数据库和连接表的操作

    1.连接测试是否连接oracle成功 (1).tnsnames.ora文件配置 oracle65= (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCO ...

  4. oracle 连接数据库以及查看当前用户、当前数据库实例

    sql>show user;查看当前用户 sql>show parameter instance_name;查看当前数据库实例 例如: sqlplus登录:用sys用户登录(密码是1234 ...

  5. oracle 连接数据库并查询,返回List<Map<String, Object>> 数据

    package JDBC; import java.sql.Clob; import java.sql.Connection; import java.sql.DriverManager; impor ...

  6. C# 连接DB2字符串 Oracle免安装客户端连接字符串

    以下是DB2连接数据库 1)使用IBM.Data.DB2链接DB2数据库 2)必须安装DB2客户端,IBM.Data.DB2在安装的BIN里可以找到 3)注意一下DB2客户端版本问题,我的就是WIN7 ...

  7. jdbc连接数据库总结

    jdbc支持多种数据库,比如说oracle, mysql, mssql,现在总结一下连接各种数据库的相关知识 1,mysql连接,代码如下 Class.forName("com.mysql. ...

  8. C#项目连接数据库的配置

    一:C# 连接SQL数据库    1.用SqlServer数据库,windows身份验证模式<add name="TestSqlSqever" providerName=&q ...

  9. oracle常见为题汇总,以及一个简单数据连接操作工厂

    本人软件环境:win8.1 64位操作系统,vs2013,安装好了与oracle数据库对应的客户端         连接oracle数据库.以及操作数据库 1.使用IIS建立网站,浏览网页时候,提示“ ...

随机推荐

  1. sublime 格式化react插件配置教程 jsfmt配置

    1.下载如下插件: https://github.com/ionutvmi/sublime-jsfmt#installation 这个插件是jsfmt,可以直接在package里搜索到: 2.user ...

  2. tips:Java中while的判断条件

    tips:Java中while的判断条件! 在c++中,有时候会遇到这种情况: while(x = y){ dosomething; } 如果x与y相等,这个时候如果循环体中没有跳出的点,那么会无限循 ...

  3. restframwork框架

    一 APIView: class PublishView(APIView): def get(self,request): publish_list=Publish.objects.all() ret ...

  4. Linux netstat命令查看并发连接数

    netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' 解释: 返回结果示例: LAST_ACK 5 (正在等待处理的 ...

  5. SOA解决方案Dubbo学习入门

    1.面向服务架构SOA简介 SOA:Service Oriented Architecture 也即现在常被提及的面向服务编程架构,其相对于传统的垂直架构来说是一种比较新的架构.

  6. 零基础学习python_类和对象(36-40课)

    今天我们开始学习面向对象的知识咯,之前我对面向对象也学的懵懵的,因为感觉知道好像又不是特别清楚,接下来我们一起来学习类和对象吧.零基础的课程我都是看小甲鱼的视频学的,没基础的可以去这个网址下载视频学习 ...

  7. 38.spiderkeeper的配置

    配置spiderkeeper管理scrapy爬虫 1.安装所需文件包pip install spiderkeeper pip install scrapyd pip install scrapy_cl ...

  8. Linux:常用命令【转载】

    转载于:https://www.cnblogs.com/yjd_hycf_space/p/7730690.html 系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架 ...

  9. jieba安装

    执行“pip install jieba”后忽略此条提示" You are using pip version 9.0.3, however version 10.0.1 is availa ...

  10. docker修改镜像名称

    [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE pujh/centos tomcat-centos 70f ...