我尝试使用Oracle。ManagedDataAccess。我的应用程序中的客户端。我将此添加到我的app.config(嵌入式资源)中:
<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.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</DbProviderFactories>
</system.data>
DBFactories列表不包含Oracle。ManagedDataAccess。客户当我将相同的条目添加到我的maschine.config(C:\Windows\Microsoft.NET\Framework\v4.0.30319\config)时,一切都很好。
<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.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
这就是我查询DBProviders的方式(但提供者列表中无论如何都不包含我的条目):
DataTable Providers = DbProviderFactories.GetFactoryClasses();
Providers.Select("InvariantName = 'Oracle.ManagedDataAccess.Client'");
那么,为什么不使用我的应用程序配置呢?我想将我的应用程序部署到客户端。我不确定我是否可以更改他们的maschine.config。
感谢您的帮助
更新:我终于找到了一个可能的解释:当我嵌入配置时(我喜欢在没有理由将配置文件放在exe旁边时这样做),它不起作用。但是,当我将配置类型更改为"nothing"并将它们放在exe旁边时,一切都很好。
有了这个配置,它终于工作了:
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
<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.121.2.0, 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.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>