C#winform应用程序未从Machine.Config获取maxTimeout值

C#winform应用程序未从Machine.Config获取maxTimeout值,c#,transactions,oracle10g,transactionscope,msdtc,C#,Transactions,Oracle10g,Transactionscope,Msdtc,我一直在使用Oracle 10g数据库开发winform应用程序,该应用程序使用的是TransactionScope,我想修改maxTimeOut在machine.config文件中指定的值,我的machine.config文件位于以下位置(我正在为此应用程序使用.net 4) 最初它没有为maxTimeOut指定任何内容,因此默认为10分钟。为了更改它,我添加了maxTimeout=“00:00:10”值,如下所示: <sectionGroup name="system.tran

我一直在使用Oracle 10g数据库开发winform应用程序,该应用程序使用的是
TransactionScope
,我想修改
maxTimeOut
machine.config文件中指定的值,我的machine.config文件位于以下位置(我正在为此应用程序使用.net 4)

最初它没有为
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>

我重新启动了电脑并运行了一个持续时间超过此时间的测试-但事务在10秒后似乎没有中止,而是使用了TransactionScopeOption参数中指定的
scopeOption。使用了TransactionScopeOption参数中指定的超时值(即5分钟),事务在5分钟后超时

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


谢谢

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

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config 
可能是winforms设置为x86编译。
还应检查是否没有odac事务超时设置和要设置的程序集。

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

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

您可以使用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));
请注意,必须将其放在config部分的末尾,否则将出现错误。
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));