Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6853309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:29:48+00:00 2026-05-27T01:29:48+00:00

Code double timeout_in_hours = 6.0; MyDataContext db = new MyDataContext(); using (TransactionScope tran =

  • 0

Code

double timeout_in_hours = 6.0;
MyDataContext db = new MyDataContext();
using (TransactionScope tran = new TransactionScope( TransactionScopeOption.Required, new TransactionOptions(){ IsolationLevel= System.Transactions.IsolationLevel.ReadCommitted, Timeout=TimeSpan.FromHours( timeout_in_hours )}, EnterpriseServicesInteropOption.Automatic ))
{
    int total_records_processed = 0;
    foreach (DataRow datarow in data.Rows)
    {
        //Code runs some commands on the DataContext (db),
        //possibly reading/writing records and calling db.SubmitChanges

        total_records_processed++;
        try
        {
            db.SubmitChanges();
        }
        catch (Exception err)
        {
            MessageBox.Show( err.Message );
        }
    }
    tran.Complete();
    return total_records_processed;
}

While the above code is running, it successfully completes 6 or 7 hundred loop iterations. However, after 10 to 20 minutes, the catch block above catches the following error:

{“The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute SQL statements.”}

The tran.Complete call is never made, so why is it saying the transaction associated with the connection is completed?

Why, after successfully submitting hundreds of changes, does the connection associated with the DataContext suddenly enter a closed state? (That’s the other error I sometimes get here).

When profiling SQL Server, there are just a lot of consecutive selects and inserts with really nothing else while its running. The very last thing the profiler catches is a sudden “Audit Logout”, which I’m not sure if that’s the cause of the problem or a side-effect of it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:29:49+00:00Added an answer on May 27, 2026 at 1:29 am

    Wow, the max timeout is limited by machine.config: http://forums.asp.net/t/1587009.aspx/1

    “OK, we resolved this issue. apparently the .net 4.0 framework doesn’t
    allow you to set your transactionscope timeouts in the code as we have
    done in the past. we had to make the machine.config changes by adding

    < system.transactions> < machineSettings maxTimeout=”02:00:00″/>
    < defaultSettings timeout=”02:00:00″/> < /system.transactions>

    to the machine.config file. using the 2.0 framework we did not have
    to make these entries as our code was overriding teh default value to
    begin with.”

    It seems that the timeout you set in TransactionScope’s constructor is ignored or defeated by a maximum timeout setting in the machine.config file. There is no mention of this in the documentation for the TransactionScope’s constructor that accepts a time out parameter: http://msdn.microsoft.com/en-us/library/9wykw3s2.aspx

    This makes me wonder, what if this was a shared hosting environment I was dealing with, where I could not access the machine.config file? There’s really no way to break up the transaction, since it involves creating data in multiple tables with relationships and identity columns whose values are auto-incremented. What a poor design decision. If this was meant to protect servers with shared hosting, it’s pointless, because such a long-running transaction would be isolated to my own database only. Also, if a program specifies a longer timeout, then it obviously expects a transaction to take a longer amount of time, so it should be allowed. This limitation is just a pointless handicap IMO that’s going to cause problems. See also: TransactionScope maximumTimeout

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Visual C++ 2008 Express Edition and when i debug code: double x
I have this line of code: double seconds = new DateTime(2006,7,6,12,1,0,DateTimeKind.Local).Subtract(new DateTime(1970,1,1,0,0,0,DateTimeKind.Local).TotalSeconds; This was
is there any advantage to using this code double x; double square = pow(x,2);
I have this in my code: double** desc = new double* [size_out]; for (int
I am using mapkit and use thin code double latitude1; double longitude1; @property (assign)
I have created an array of doubles using the following code: double *points =
I have the following line of code: double *resultOfMultiplication = new double(*num1 * *num2);
I am using Visual studio 2008. For below code double main() { } I
I'll try to explain this problem the best way i can with code: double
Checkstyle reports this code as The double-checked locking idiom is broken, but I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.