我收到这个错误
必须先处理事务,然后才能使用连接执行 sql 语句。
我有一个包含大约 6000 行的 Excel 文件,我将这些文件上传到类型化数据集中的数据表中,然后我尝试将我的业务逻辑应用于 dt 中的这些行。
第二个循环抛出异常,我必须执行两个循环;为什么会出现这个异常,我该如何解决?
这是我的代码:
try
{
using (TransactionScope scope = SysInfo.BeginTransaction(IsolationLevel.Serializable))
{
//Here is my Typed dataset
//Method Looping through row in Datatable & Calling DB
//another Method Looping through row in Datatable & Calling DB
scope.Complete();
}
}
catch (Exception ex) { throw ex; }
我通过在 App.config 中添加以下行解决了这个问题:
<configuration>
<system.transactions>
<defaultSettings timeout="00:01:30" />
</system.transactions>
</configuration>
在 Machine.config 中:
<configuration>
<system.transactions>
<machineSettings maxTimeout="00:01:30" />
</system.transactions>
</configuration>
由于这个过程需要很长的时间,超过 10 分钟,所以我发现我需要用更高的值覆盖这个值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)