为ODP.NET

时间:2016-05-09 10:42:19

标签: .net oracle app-config dbproviderfactories machine-config

我尝试在我的应用程序中使用Oracle.ManagedDataAccess.Client。我将此添加到我的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.Client。当我将相同的条目添加到我的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旁边时这样做)它不起作用。但是,当我将config-type更改为“nothing”并将它们放在exe旁边时,一切正常。

1 个答案:

答案 0 :(得分:0)

通过这种配置,它终于奏效了:

<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>