سؤال

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

هل كانت مفيدة؟

المحلول

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> 

نصائح أخرى

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.

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));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top