Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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; }   
like image 992
hatem Avatar asked Jun 28 '12 16:06

hatem


1 Answers

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.

like image 86
hatem Avatar answered Sep 19 '22 00:09

hatem