前连接可用于执行SQL语句的交易必须进行处理 [英] the transaction must be disposed before the connection can be used to execute sql statements

查看:264
本文介绍了前连接可用于执行SQL语句的交易必须进行处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误




事务必须设置在连接可用于执行SQL语句之前。**。




我有一个包含约6000行,我在类型化的DataSet上传这些文件到数据表中的Excel文件,然后我试图申请在DT这些行我的业务逻辑,这里是我的代码
异常从第二循环罚球和我必须做2路,我需要帮助知道为什么会出现这样的异常,我该如何解决这个问题。

 
{
使用(TransactionScope的范围= SysInfo.BeginTransaction(IsolationLevel.Serializable))
{

//这里是我的类型化的DataSet

//方法通过行的DataTable和放循环;调用DB

//另一种方法通过行的DataTable和放循环;调用DB

scope.Complete();
}
}
赶上(例外前){抛出前; }


解决方案

我解决它通过添加以下线应用.config文件:

 <结构> 
<&System.Transactions的GT;
< defaultSettings超时=00:01:30/>
< /system.transactions>
< /结构>

和本Machine.config中:

 <结构> 
<&System.Transactions的GT;
< machineSettings maxTimeout =00:01:30/>
< /system.transactions>
< /结构>



因为这个过程需要很长的时间大于10分钟,所以我发现我需要覆盖这个值高一位。



但我有一个问题,什么是例子吧。


增加超时值的影响

I am getting this error

The transaction must be disposed before the connection can be used to execute sql statements.**.

i have an Excel file that contains about 6000 rows and i uploaded these file into Data table in typed dataset ,then i am trying to apply my business logic on these rows in dt,here is my code the exception throws from the second loop and i have to do 2 loops ,i need help to know why this exception occurs and how can i solve it.

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

解决方案

I solved it by adding the below lines in App.config:

<configuration>
    <system.transactions>
        <defaultSettings timeout="00:01:30" />
    </system.transactions>
</configuration> 

and this in Machine.config:

<configuration>
    <system.transactions>
        <machineSettings maxTimeout="00:01:30" />
    </system.transactions>
</configuration>

as this process takes a very long time greater than 10 minutes ,so i found that i need to overwrite this value with a higher one.

but i have one question, what is the effect of increasing timeout value with example please.

这篇关于前连接可用于执行SQL语句的交易必须进行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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