.net - Oracle .net Provider CommandTimeout 不起作用

标签 .net oracle command-timeout

我正在尝试更改 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 秒,但没有引发异常。

最佳答案

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

之前在一些网络配置中见过这个问题。尝试使用Disable_Oob=on。自述文件中的更多信息:http://www.oracle.com/technetwork/topics/dotnet/downloads/odpnet-managed-nuget-12102400-2718787.txt ...

关于.net - Oracle .net Provider CommandTimeout 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41356038/

相关文章:

c# - 在 C# 中对 ListView 进行排序时忽略 "The"和 "A"

c# - 在从 C# 调用的 DLL 中使用 std::cout

c# - 使用静态数据的WCF服务遇到问题

oracle - 创建返回 XML 和 JSON 的 Oracle APEX Restful 服务

asp.net-mvc - 在 EF 6 中设置命令超时

c# - 我应该如何存储我的自定义类?

Java/C# 程序访问 Oracle 数据库,字符串中的字符错误

Oracle 首选列长度

sql-server - SMO ConnectionContext.StatementTimeout 设置被忽略

c# - 将 SqlCommand 的 CommandTimeout 设置为高值是否有任何负面影响?