.NET 错误的 DbProviderFactories
我在让 ODP.NEt 库与 .NET DBProviderFactories 一起使用时遇到问题。我使用此代码收到以下错误:
_DBFactory = DbProviderFactories.GetFactory(providerName);
为 system.data 创建配置节处理程序时发生错误:列“InvariantName”被限制为唯一。值“Oracle.DataAccess.Client”已存在。
使用此提供程序名称:Oracle.DataAccess.Client
以及 web.config 中的以下条目:
<system.data>
<DbProviderFactories>
<add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description=".Net Framework Data Provider for Oracle" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=10.2.0.100, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
有谁知道出了什么问题?我不认为我在任何地方都设置了两次。
I am having trouble getting the ODP.NEt library to work with the .NET DBProviderFactories. I am getting the following error with this code:
_DBFactory = DbProviderFactories.GetFactory(providerName);
An error occurred creating the configuration section handler for system.data: Column 'InvariantName' is constrained to be unique. Value 'Oracle.DataAccess.Client' is already present.
with this providerName: Oracle.DataAccess.Client
And the following entry in the web.config:
<system.data>
<DbProviderFactories>
<add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description=".Net Framework Data Provider for Oracle" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=10.2.0.100, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
Does anyone know what is wrong? I don't think I have it set up twice anywhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您安装了 ODP.net(例如,使用 oracle 通用安装程序,而不是 xcopy),您将在 machine.config 中找到相同的 DbProviderFactories/add。
因此,将其添加到您的 web.config 中就是第二次添加它 - 因此,复制 Oracle.DataAccess.Client!
If you installed ODP.net (eg using the oracle universal installer, as opposed to xcopy), you'll find the same DbProviderFactories/add in machine.config.
So adding it in your web.config is adding it a second time - so, duplicate Oracle.DataAccess.Client!
下面的事情你能做到吗? (注意“清楚”)
Can you do the below? (Note the "clear")
应该注意的是,
将清除所有您可能不希望执行的DbProviderFactories
,具体取决于您的情况。您还可以在重新添加该类之前通过添加以下行来删除该类:
以下是整个
< system.data>
看起来:如果您的本地计算机和服务器环境没有匹配的配置文件(例如 machine.config),这可能很有用。
您可以做的另一件事就是将其从您的 web.config 中一起删除,假设您的 machine.config 中的设置可以工作。但是,我会在您的开发计算机和服务器上对此进行测试。就我而言,它适用于其中一个,但不适用于另一个,因为 machine.config 文件不匹配。为了解决这个问题,我将相同的设置添加到服务器上的 machine.config 中,而没有
,如下所示:It should be noted that
<clear />
will clear allDbProviderFactories
which you may not want to do, depending on your situation.You could also just remove that class right before you re-add it by adding this line:
<remove invariant="Oracle.ManagedDataAccess.Client" />
Here's how the whole
<system.data>
would look:This can be useful if your local machine and server environments don't have matching config files such as machine.config.
The other thing you could do is just remove it from your web.config all together assuming the setting in your machine.config will work. However, I would test this on both you development machine and your servers. In my case, it worked on one but not the other because the machine.config files didn't match. To resolve, I added this same setting to the machine.config on the server without the
<remove invariant="Oracle.ManagedDataAccess.Client" />
like so:最有可能的是机器配置文件 DbProviderFactories 部分崩溃了。
检查是否有多余的Oracle.DataAccess.Client行,卸载oracle客户端后仍然存在。
Most probably the machine config file DbProviderFactories section crashed.
Check if there is extra Oracle.DataAccess.Client line, which still remains after uninstall oracle client.