【问题标题】:maxTimeout value from Machine.Config is not picked up by C# winform appC# winform 应用程序未获取 Machine.Config 中的 maxTimeout 值
【发布时间】:2013-04-29 14:27:22
【问题描述】:

我一直在使用 Oracle 10g 数据库开发一个 winform 应用程序,该应用程序使用 TransactionScope,并希望修改 ma​​chine.config 文件中指定的 maxTimeOut 值,我的 机器。 config 文件位于以下位置(我为此应用使用 .net 4)

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config 

最初没有为 maxTimeOut 指定任何内容,因此默认为 10 分钟。为了改变它,我添加了maxTimeout="00:00:10" 值,如下所示:

    <sectionGroup name="system.transactions" type="System.Transactions.Configuration.TransactionsSectionGroup, System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null">
        <section name="defaultSettings" type="System.Transactions.Configuration.DefaultSettingsSection, System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null"/>
        <section name="machineSettings" type="System.Transactions.Configuration.MachineSettingsSection, System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null" allowDefinition="MachineOnly" allowExeDefinition="MachineOnly" maxTimeout="00:00:10"/>
    </sectionGroup>

我已重新启动 PC 并运行了一个持续时间比这更长的测试 - 但事务似乎在 10 秒后没有中止,而是使用了在 TransactionScopeOption 参数中指定的 scopeOption.TimeOut 值(即 5 分钟),并且交易在 5 分钟后超时。

我是否将 maxTimeout 值包含在上面的正确位置?文件中有什么需要更改的吗?为什么没有使用 machine.config 中的 maxTimeout 值?

谢谢

【问题讨论】:

    标签: c# transactions oracle10g transactionscope msdtc


    【解决方案1】:

    它没有被拾取的原因是因为 maxTimeOut 值应该放在 machine.config 文件的末尾,就在关闭配置标记之前。一旦我这样做了,它就开始工作了。

    <configuration>
        <!-- Other configuration sections-->
        <system.transactions>
            <machineSettings maxTimeout="01:00:00" />
        </system.transactions>
    </configuration> 
    

    【讨论】:

    • 注意,你必须把它放在config部分的end,否则会报错。
    【解决方案2】:

    尝试在 32 位机器配置中设置值

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config 
    

    可能是 winforms 设置为 x86 编译。 还要检查是否没有要设置的 odac 事务超时设置和程序集。

    【讨论】:

      【解决方案3】:

      您可以使用 s_maximumTimeouts_cachedMaxTimeout 来覆盖该值

      Type oSystemType = typeof(global::System.Transactions.TransactionManager);
      System.Reflection.FieldInfo oCachedMaxTimeout = 
                          oSystemType.GetField("_cachedMaxTimeout", 
                          System.Reflection.BindingFlags.NonPublic | 
                          System.Reflection.BindingFlags.Static);
      System.Reflection.FieldInfo oMaximumTimeout = 
                          oSystemType.GetField("_maximumTimeout", 
                          System.Reflection.BindingFlags.NonPublic | 
                          System.Reflection.BindingFlags.Static);
      oCachedMaxTimeout.SetValue(null, true);
      oMaximumTimeout.SetValue(null, TimeSpan.FromSeconds(2400));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-19
        • 2017-06-16
        • 1970-01-01
        • 1970-01-01
        • 2015-09-16
        • 2019-03-02
        • 1970-01-01
        • 2014-09-16
        相关资源
        最近更新 更多