Oracle ODP.NET 错误

Oracle ODP.NET error

我有一个 VS 2012 Web 项目。我安装了 ODP.NET,因为我们是 Oracle Workshop。我继承了一个使用 Oracle.ManagedAccess.Data 和 EF 的项目。

在 运行 VS 2012 中的项目中,我收到以下错误:

There is a duplicate 'oracle.manageddataaccess.client' section defined..

解决方案是禁用 web.config

中的以下行
<!--<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />-->

很好。该项目已编译,但在执行一个简单的命令(例如在必须读取数据库的地方取回密码)时,出现了另一个错误:

System.Data.ConstraintException: Column 'InvariantName' is constrained to be unique.  Value 'Oracle.ManagedDataAccess.Client' is already present.

现在我知道错误是由 ODP.NET 引起的,并且它存在于 GAC 中,因此双重错误报告。

是否还有另一行我应该注释掉,或者有没有办法暂时禁用 ODP.NET?我不想安装该客户端,因为我将它用于其他项目。

谢谢

我在 Oracle site 上找到了关于 "There is a duplicate 'oracle.manageddataaccess.client' section defined." 的以下内容:

If your application is a web application and the above entry was added to a web.config and the same config section handler for "oracle.manageddataaccess.client" also exists in machine.config but the "Version" attribute values are different, an error message of "There is a duplicate 'oracle.manageddataaccess.client' section defined." may be observed at runtime. If so, the config section handler entry in the machine.config for "oracle.manageddataaccess.client" has to be removed from the machine.config for the web application to not encounter this error. But given that there may be other applications on the machine that depended on this entry in the machine.config, this config section handler entry may need to be moved to all of the application's .NET config file on that machine that depend on it.

希望对您有所帮助。

就我而言,我有多个项目。一个是 Entity Framework 数据模型,另一个是使用 EF 模型的 WCF 服务,一个使用 WCF 服务的 WPF 项目,最后是我的 ASP.NET MVC 项目,使用 Entity Framework 数据模型直接地。 我们使用 Oracle 并有一个 Nuget 包 oracle.manageddata。除了我的 ASP 项目(其版本为 12.1.22)之外,我在所有其他项目中都使用了版本 12.1.21。降级到其他项目正在使用的版本后,我的 Web ASP 又变成了 运行。在不同的项目中使用不同的 Nuget 版本,在同一个解决方案中,似乎并不是一个好主意。

我在 ASP.Net MVC 项目中遇到了同样的错误。我发现项目的 Web.config 中的 oracle.manageddataaccess.client

中的 machine.config 版本不匹配
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config, and 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config. 

我在 Web.config 中有 Version=4.122.18.3,在 machine.config 中有 Version=4.122.1.0

我更新了machine.config中的版本(替换了oracle.manageddataaccess.client with 4.122.18.3Version=4.122.1.0),问题解决了。