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

你说的曾经没有我的故事 提交于 2019-12-10 17:00:04

问题


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.

The exception throws from the second loop and I have to do two loops; why does this exception occur, and how can I solve it?

Here is my code:

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

回答1:


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.



来源:https://stackoverflow.com/questions/11248943/the-transaction-must-be-disposed-before-the-connection-can-be-used-to-execute-sq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!