5

我正在尝试更改 OracleCommand 查询的命令超时,但它不起作用,因此不会触发超时异常。

  • 使用 Oracle.ManagedDataAccess.dll (4.121.2.0)

    using (OracleConnection _connection = new OracleConnection(connectionString))
    {
    
        using(OracleCommand command = _connection.CreateCommand())
        {
    
          command.CommandText = commandText;
          command.CommandTimeout = 10;
    
         _connection.Open();
          using(OracleDataReader reader = command.ExecuteReader())
          {
              while (reader.Read())
              {
                    Console.WriteLine(reader.GetValue(0));
              }
           }
        } }
    

配置:

<configSections>
    <section name="entityFramework"
      type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
      requirePermission="false"/>
    <section name="oracle.manageddataaccess.client"
      type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
      <provider invariantName="Oracle.ManagedDataAccess.Client"
        type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </providers>
  </entityFramework>
  <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>
  <oracle.manageddataaccess.client>
    <version number="*">
      <dataSources>
        <dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xxx)(PORT=1561))(CONNECT_DATA=(SERVICE_NAME=xxxx))) "/>
      </dataSources>
    </version>
  </oracle.manageddataaccess.client>
  <connectionStrings>
    <add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=xxxx;Password=xxxx;Data Source=SampleDataSource"/>
  </connectionStrings>

此查询运行超过 10 秒,但未引发异常。

4

2 回答 2

2

将设置 Disable_Oob 添加到 App.config 对我有用:

...
<oracle.manageddataaccess.client>
     <version number="*">
       <settings>
         <setting name="Disable_Oob" value="on" />
       </settings>
       <dataSources> 
    ...
于 2018-04-19T12:11:39.150 回答
2

Oracle .net 团队解决了我的问题 :)

之前通过一些网络配置看到过这个问题。尝试使用 Disable_Oob=on。README 中的更多信息:http ://www.oracle.com/technetwork/topics/dotnet/downloads/odpnet-managed-nuget-12102400-2718787.txt ...</p>

于 2016-12-28T20:59:47.460 回答