如何在c#中增加事务范围时间 [英] How to increase transaction scope time in c#

查看:189
本文介绍了如何在c#中增加事务范围时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,



我在我的应用程序中使用简单的事务范围,在其中我将员工记录插入两个不同的数据库,



我使用批量上传来插入更改,使用csv文件检索数据并将字段插入表格。



现在当数据很大时我会遇到超时事务范围问题。



我使用的是dot net framework 4.0



请建议,我试图给时间跨度到事务范围类的构造函数..但仍然超时问题..

解决方案

试试这个 -



在Machine.config中



 <  配置 >  
< system.transactions >
< machinesettings maxtimeout = 00:30:00 / >
< / system.transactions >
< / configuration >





在App.config中

< pre lang =HTML> < system.transactions >
< defaultsettings timeout = 00:30:00 / >
< / system.transactions >





如果这不起作用,请告知我们。


 //这用于将事务超时设置为40分钟。 
类型objSystemType = typeof(global :: System.Transactions.TransactionManager);
System.Reflection.FieldInfo oCachedMaxTimeout = objSystemType.GetField(_ cachedMaxTimeout,System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
System.Reflection.FieldInfo oMaximumTimeout = objSystemType .GetField(_ maximumTimeout,System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
oCachedMaxTimeout.SetValue(null,true);
oMaximumTimeout.SetValue(null,TimeSpan.FromSeconds(2400));

//用于测试以确认值已更改
// var show =(string.Format(DEBUG SUCCESS !!事务的最大超时为{0},TransactionManager.MaximumTimeout。的ToString()));


Hii ,

I am using simple transaction scope in my application , inside which i am inserting employee records into two different database ,

I am using bulk upload to insert the changes , using csv file it retrieves the data and insert the field into the tables .

Now when the data is large i am getting timeout transaction scope problem .

I am using dot net framework 4.0

Please suggest , i tried to give time span into the constructor of transaction scope class .. but still timeout issue ..

解决方案

Try this-

In Machine.config

<configuration> 
  <system.transactions>
    <machinesettings maxtimeout="00:30:00" />
  </system.transactions>
</configuration> 



In App.config

<system.transactions>
     <defaultsettings timeout="00:30:00" />
</system.transactions>



In case this doesn't work, please let me know.


// This is used for set the transaction timeout to 40 minutes.
Type objSystemType = typeof(global::System.Transactions.TransactionManager);
System.Reflection.FieldInfo oCachedMaxTimeout = objSystemType.GetField("_cachedMaxTimeout", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
System.Reflection.FieldInfo oMaximumTimeout = objSystemType .GetField("_maximumTimeout", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
oCachedMaxTimeout.SetValue(null, true);
oMaximumTimeout.SetValue(null, TimeSpan.FromSeconds(2400));

// For testing to confirm value was changed
// var show=(string.Format("DEBUG SUCCESS!!  Maximum Timeout for transactions is {0}", TransactionManager.MaximumTimeout.ToString()));


这篇关于如何在c#中增加事务范围时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆