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 9160353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:43:09+00:00 2026-06-17T13:43:09+00:00

I use MySQL (it does not support MARS), and I try to run in

  • 0

I use MySQL (it does not support MARS), and I try to run in parallel multiple SELECTs. The connection string is the same, however for each SELECT I create another db context.

It looks like this:

using (var db = DataContextCreator.Instance.Create())
{
  return db.Customers
           .Where(it => it.customer_Id > 10)
           .Detach(db.Customers);
}

A word about Detach — it is helper method which takes a record or bunch of records. In the second case it makes the list of them (to make them concrete data), and detaches the records from db context (so GC could free the db context) returning back the detached data.

For now it gives me an error about dreadful “There is already an open DataReader associated with this Connection which must be closed first”. Since I don’t explicitly use DataReader I would like be 100% sure of the reason.

Is it because I use single connection string to create all those db contexts? Or put in other words — is MARS required for above scenario?

I am asking because I would like not to reinvent the wheel, and because all my queries are rather small and quick I am thinking about stupid workaround — using lock in db context creator. This way each block querying database would have guarantee that is not executed in parallel with another one.

  • 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-06-17T13:43:10+00:00Added an answer on June 17, 2026 at 1:43 pm

    MARS is only a factor when you are running multiple queries at the same time on a single SqlConnection object.

    Generally, every DbContext object will have its own DbConnection object, so that is probably not the issue here.

    I think the issue here is that, by calling the Detach method, you are probably calling the query while it is still executing.

    I would suggest using the AsNoTracking extension methods to achieve your goals.

    That is, I would write the function return as:

    return db.Customers.Where(it => it.customer_Id > 10).AsNoTracking().ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use InnoDB on RDS, which unfortunately does not yet support MySQL full text
I would like to use ORDER BY FIELD() (MySQL) in Django. Does Django support
hibernate xml mapping file does not support default value. So when i try to
As some of you may know, use of the LIMIT keyword in MySQL does
MySQL uses the USE database_name to change the active database. Does that work on
Possible Duplicate: Anyone know of a good PHP ORM that DOES NOT use PDO?
I use MySQL 5.5.16. I'm trying to check if a certain column exists in
We use MYSQL InnoDB engine for insert and update operations, in order to improve
I'm trying to use MySQL and ebeans for saving my tasks. When i apply
I'd like to use MySQL from SilkJS under OSX Lion, but can't find the

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.