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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:59:13+00:00 2026-05-13T00:59:13+00:00

I have this web app that is running ASP .NET MVC 1.0 with LINQ

  • 0

I have this web app that is running ASP .NET MVC 1.0 with LINQ 2 SQL

I’m noticing a very strange problem with LINQ 2 SQL throwing exceptions (mainly Specified cast invalid or Sequence contains more than one element) when under a certain amount of load.

The bigger problem is, I’m not talking about Real Heavy/Professional Stress Testing… Basically what I’m doing is I open FireFox and Chrome and hold down F5 for ten seconds in each (I call this poor man stress testing) – lo and behold; the web app is throwing these exceptions randomly for the next two or five minutes. If I restart the app from IIS7 (or restart WebDev if under Visual Studio) then immediately all is back to normal. Like nothing happened.

At first I was suspecting the way I handle the DataContext, maybe i’m supposed to dispose it at every Application_End from Global.asx, but that didn’t change anything.

Right now I have a single public static DataContext object used by all requests. I’m not disposing it or re-creating it. Is that the right way to do it? Am I supposed to dispose it? When exactly should I dispose it?

There are several things that happen on every request – for example, in every page, the User object (for the current user) is loaded from the database and “LastSeen” attribute is updated to DateTime.Now. Other things (like Tag Cloud for example) are cached.

Any ideas why this is happening?

  • 1 1 Answer
  • 1 View
  • 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-13T00:59:13+00:00Added an answer on May 13, 2026 at 12:59 am

    The DataContext class is not threadsafe – you need to create a new one for each operation. See this article by Rick Strahl (Linq to SQL DataContext Lifetime Management)

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

Sidebar

Related Questions

I have a SQL query in my ASP.net web app that looks like this:
i have an asp.net website http://www.site.com . This web app is also running on
I have an asp.net mvc web app that has controllers with role attributes on
I have an ASP.NET Web Forms app that I am building and running against
I have just recently run into an issue running an asp.net web app under
I have ASP.NET MVC Beta on our web server running a few apps. My
I have an existing ASP.NET web application that I'm converting to MVC 1.0. The
Hey everyone.. This is my first time writing an ASP.NET MVC web app, and
I have an asp.net MVC web application that requires tasks to be scheduled. (A
I have a major problem. We have a asp.net application that has this report

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.