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

  • SEARCH
  • Home
  • 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 4127038
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:06:42+00:00 2026-05-21T00:06:42+00:00

I have to insert 2 records in to one db and around 40 records

  • 0

I have to insert 2 records in to one db and around 40 records in to another db in a single transaction. I am using TransactionScope and getting this error.

I did read this article but that does not help because there are 2 db’s are involved and it is a Distributed Transaction.

http://www.devart.com/blogs/dotconnect/index.php/entity-framework-tips-and-tricks-part-3.html

My code is somewhat like below.

using (var ts  = new TransactionScope()) {
    using (var context = new MyContext()) {
      for (int i = 0; i < 40; i++)
      {
        var order = context.Orders.Where(a => a.name = 'xxx').Single();
        context.ArchiveOrders.Add(order);
      }
    }
}

Even though I am creating the “Context” outside my loop(unlike the example in the link above), the code still fails with the “too many local sessions” error.

Also, I noticed that every query “context.Orders.Where(…)” is enlisted as a new Transaction. I am using Entity Framework and not Linq to Sql. So the above code breaks at 20 iterations.

What are my options now apart from making them 2 independent local transactions and do the transaction handling manually somehow.

  • 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-21T00:06:43+00:00Added an answer on May 21, 2026 at 12:06 am

    We have replied to you here at our forum.
    The solution is to add context.Connection.Open(); before the loop.

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

Sidebar

Related Questions

I have to insert 8000+ records into a SQLite database using Django's ORM. This
I have the following table. When i try to insert records using LINQ to
What happens in mysql multiple records insert during an error. I have a table:
I have to insert 3 records in one time: INSERT INTO table (id, name,
I have one service in C# which fetch records from oracle DB and insert
One has txtDateReceived and second has txtVendorPackDate. Before insert will add record I have
I have a gridview and sqldatasource. I'm trying to insert new records in database
I Have a set of choices(options) coming from Database(around 36 records) which I have
I'm just getting my head around insert statements today after getting sick of cheating
I have three tables and three stored procedures respectively to insert/update records in these

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.