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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:44:14+00:00 2026-06-11T01:44:14+00:00

I have a simple ASP.NET hosted WCF Service that has several methods that all

  • 0

I have a simple ASP.NET hosted WCF Service that has several methods that all have the same pattern when it comes to using the Entity Framework…

public void Operation1(string username)
{
    using(MyEFContext context = new MyEFContext())
    {
        UserInfo info = (from ui in context.UserInfos
                         where ui.User.Equals(username)
                         select ui).FirstOrDefault<UserInfo >();

        info.LastAccess = DateTime.Now;

        // Operation specific code, such as getting information using the EF context

        context.SaveChanges();
    }
}

This is a cut down version to keep the example simple but even this simple version has the same error as my production set of code. The code starts by getting the users information using the Entity Framework, updates the users LastAccess field and then performs the operation specific code. The operation specific code just makes queries for information. At the end it calls SaveChanges so the LastAccess is saved back to the database. Now this all works perfectly fine until my client makes two calls in parallel.

The client makes two calls, each to a different operation but they both have the same pattern of code as seen above. Sometimes both calls complete with success. But other times one of them will produce as error and it could be any of the following three…

System.Data.EntityException: The underlying provider failed on Open. ---> 
System.InvalidOperationException: The connection was not closed. The connection^s current 
state is connecting.

System.Data.EntityCommandExecutionException: An error occurred while executing the command
definition. See the inner exception for details. ---> System.InvalidOperationException: 
ExecuteReader requires an open and available Connection. The connection^s current state is 
closed.

System.InvalidOperationException: Invalid attempt to read when no data is present.

Clearly my understanding of EF and ASP.NET is flawed because I expected the two operations to work even in parallel. Do I need to put a lock around each method so they only occur one at a time? Surely not. Any ideas?

  • 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-11T01:44:16+00:00Added an answer on June 11, 2026 at 1:44 am

    Found the answer here Managing EntityConnection lifetime. Turns out that reusing the same EntityConnection instance for all my contexts was the issue. So now I create a new one each time.

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

Sidebar

Related Questions

I have a WCF Service hosted in IIS/ASP.NET that accepts HTTP Post ( not
We have a simple ASP.Net WCF Ajax enabled web service which is called via
I have a simple .NET 4 WCF service which I have hosted locally on
I am designing a simple C# WCF service using ASP.NET 4.0 and hosted on
I have a pretty simple ASP.NET Web Form that looks a bit like the
What I have created a very simple asp.net web service using .NET framework 3.5,
I use WCF for an ASP.Net MVC 2 Application. And when the service has
We have a couple of WCF services hosted in an asp.net application on IIS.
I have put together a simple ASP.NET MVC 3 test web app that uses
I have a very simple asp.net mvc3 app that uses jquery::getJSON to call into

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.