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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:39:17+00:00 2026-05-13T09:39:17+00:00

I’m running ASP.NET MVC 2 Preview 2 (With VS 2010 Beta 2) using Entity

  • 0

I’m running ASP.NET MVC 2 Preview 2 (With VS 2010 Beta 2) using Entity Framework.

Earlier yesterday, for some unknown reason, a single page in my app started to load very slowly on my host.

The problem is, this only occurs on my host and I haven’t changed anything for it to load slow.

Here is the action that is loading very slow:

public ActionResult Index()
{
    MyEntitiesContext db = new MyEntitiesContext();
    IEnumerable<City> cities = db.Cities.Where(x => x.Orders.Count != 0).OrderBy(x => x.Name);
    return View(cities);
}

and this is my Index.aspx

       <ul>
         <% foreach (City g in Model){ %>
            <li>
              <%= Html.ActionLink(g, "View", "Cities", new { CityID = g.CityID}, null)%>(<%= g.City %>)
           </li>         
         <% } %>
       </ul>

Now this works perfectly fine on my dev machine, and it worked fine on my host until late last night.

Here are some diagnostics I tested:

  1. The code works/loads fine on my dev machine using my dev machine’s SQL database
  2. When I switch the connection string on my dev machine app to my hosts sql server, the code takes forever to load
  3. When I run the LINQ against my dev machine SQL server using LINQ Pad it runs quick (.3 seconds) and when I run it against my host’s SQL server it also runs quick (.3 seconds)
  4. One time I used my host’s SQL server for the connection string and ran the app in VS 2010 debug, after a some time, I received this error

    Execution of the command requires an open and available connection. 
    The connection's current state is broken.
    

The table Cities has over 7000 rows, with (as of now) only about 4-5 rows that actually have Orders (so those are the ones that will be displayed).

I talked to my host, they said they don’t see anything wrong with the server (Which makes sense because other pages on the website that query the server run fine). They restarted it, but I’m still getting the same slow load times.

This is a weird problem, I have no idea what could be causing this, any help would be greatly apprecaited.

UPDATE 1:

Here is the stop watch results

        Stopwatch s = new Stopwatch();
        s.Start();
        IEnumerable<City> cities = db.Cities.Where(x => x.Orders.Count != 0).OrderBy(x => x.Name);
        s.Stop();
        long t = s.ElapsedTicks;
        return View(cities);

When I place a break point at return View(cities), t had the value of 387 which makes sense since cities is just making the statement, which also means the issue lies in the foreach that executes the statement in the view.

Since I can’t put break points into the view, I went ahead and did the following:

        s.Start();
        List<City> list = cities.ToList();
        s.Stop();
        long q = s.ElapsedTicks;

to mimic executing the statement (from my understanding, running a foreach on an IEnumerable is equivalent to calling .ToList())

After a very long time (note: I’m still using my shared host’s SQL server in the connection string), q’s value was 890489194. So the issue is executing the query. Is this an obvious indication to an issue with the SQL database/server?

Update 2:

If I rewrite the query as such:

  db.Orders.Select(x => x.City).Distinct();

This runs fast and the page loads fine. My only concern is scaling. Which query would be better for a large database.

Again, each Order has a single City associated with it, and a City can have many Orders.

  • 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-13T09:39:18+00:00Added an answer on May 13, 2026 at 9:39 am

    I am going to just come out and say you need an index for the join to your Order table.

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

Sidebar

Ask A Question

Stats

  • Questions 367k
  • Answers 367k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer NOTE: This requires jQuery UI (not just jQuery). You can… May 14, 2026 at 4:55 pm
  • Editorial Team
    Editorial Team added an answer I've manage to pass exception into ModelState by overriding MvcContrib.FluentController.AbsteactFluentController.ExecuteCheckValidCall(Func… May 14, 2026 at 4:55 pm
  • Editorial Team
    Editorial Team added an answer It's definitely not Django issue. As far as I understood… May 14, 2026 at 4:55 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.