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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:50:38+00:00 2026-06-17T07:50:38+00:00

I have two functions that execute two ajax calls. If I call one function

  • 0

I have two functions that execute two ajax calls. If I call one function and not the other
the code executes normally. But if I call both of them at the same time I get two Internal Server errors messages. One for each function I presume.

This is my code:

   $(document).ready(function(){
         CategoryChangeState(@Model.CatId , subcategoryId);
         SubategoryChangeState(@Model.SubcatId);
    })
    public ActionResult ReturnListOfSubcategories( FormCollection collection ) {
            string categoryId = collection["result"];

            var subcategories = ProductManagerHelperClass.ReturnSubcategories(categoryId);
            return Json(subcategories);
    }
    public ActionResult ReturnListOfBrands() {

          var brands = ProductManagerHelperClass.ReturnBrands();
          return Json(brands);
    }
function CategoryChangeState(value ,  editPage) {
        .....
        $.ajax({
            type: "POST",
            url: "/ProductManager/ReturnListOfSubcategories",
            data: { result: value },
            datatype: "json",
            error: function (jqXHR, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
        ...
}

function SubategoryChangeState(value) {
         ....
         $.ajax({
            type: "POST",
            url: "/ProductManager/ReturnListOfBrands",
            datatype: "json",
            error: function (jqXHR, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
       ....
}

Why am I getting these errors and how can I solve it?

EDIT

While debugging I discovered that in this portion of code:

 public static Dictionary<string , string> ReturnSubcategories(string categoryId)
    {
        int catId = int.Parse(categoryId);

        var subcategories = (from s in dataContext.SubCategories
                             where s.CatId == catId
                             select new
                                        {
                                            s.SubCatId,
                                            s.SubCatName
                                        }).ToDictionary(x => x.SubCatId.ToString(), x => x.SubCatName);

        return subcategories;
    } 

The linq query throws an exception:

InvalidOperationException ExecuteReader requires an open and available Connection. The connection's current state is closed.

Again this exception is only thrown if I call both functions

  • 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-17T07:50:40+00:00Added an answer on June 17, 2026 at 7:50 am

    That’s because you use a static class, in which you (probably) make a connection to your database.
    The following happens:

    1. Thread one enters your static class, a connection is opened.
    2. In the meanwhile thread two enters the same class, and uses the same open connection.
    3. When thread one is done, it closes the open connection.
    4. Thread two throws an error because there is no open connection.

    This won’t happen if you don’t use a static class to instantiate database connections.

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

Sidebar

Related Questions

I have code that is part of an $.ajax call to MVC. Two functions
I have two JS functions that preforms AJAX calls, I've wanted to test them
I have two Ajax functions that are on the same div, the first one
I have two functions that return simple strings. Both are registered. $.views.helpers({ parseDate: function
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
I have two functions, one which parses all the arguments sent to the function
I have an Ajax jquery function ($.post) that retrieves json data. One of the
I have two def functions that I call in a nested fashion and want
I have form autocomplete code that executes when value changes in one textbox. It
Let's say for example that I have two functions with random code inside and

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.