maxTimeout value from Machine.Config is not picked up by C# winform app
Asked Answered
C

3

6

I have been working on a winform app with Oracle 10g database which is using TransactionScope and wanted to modify the maxTimeOut value specified in machine.config file, my machine.config file is in the following location (I am using .net 4 for this app)

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

Originally there was not anything specified for maxTimeOut in it, therefore it defaults to 10 minutes. In order to change it I have added the maxTimeout="00:00:10" value as seen below:

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

I have restarted the PC and ran a test that lasted longer than this - but the transaction does not appear to abort after 10 seconds, instead the scopeOption.TimeOut value (which is 5 min) specified in TransactionScopeOption parameter is used and the transaction times out after 5 minutes.

Have I included the maxTimeout value into the right place above? Is there anything that needs changing in the file? Why is the value of maxTimeout from machine.config not being used?

Thanks

Conversant answered 29/4, 2013 at 14:27 Comment(0)
C
25

The reason it was not picked up was because the maxTimeOut value should be placed at the end of the machine.config file just before the closing configuration tag. As soon as I have done it this way it started working.

<configuration>
    <!-- Other configuration sections-->
    <system.transactions>
        <machineSettings maxTimeout="01:00:00" />
    </system.transactions>
</configuration> 
Conversant answered 30/4, 2013 at 20:10 Comment(1)
Note that you must put this at the end of the config section, otherwise you will get an error.Heterolysis
M
2

try setting the value in the 32bit machine config

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

Could be that the winforms is set for x86 compilation. Also check that there isnt an odac transaction timeout setting and assembly to set as well.

Mer answered 29/4, 2013 at 14:37 Comment(0)
T
1

you can use s_maximumTimeout,s_cachedMaxTimeout to override the value

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));
Third answered 5/11, 2020 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.