views:

157

answers:

1

Hi,

Recently i implemented Linq to SQL in a static class in my ASP.Net project which is a utility class to get some information on site load. when i used the static linqtosql datacontext i got the above error only in the live environment but never got that issue on UAT, or QA sites. ( this means this issue only happens when there is a much of a load).

so i googled around and found this article here. so what i did was i made my page level datacontext variables and passed them to the static methods every time i call them. is what i did was correct, will that resolve this issue ?/

+1  A: 

In ASP.Net each request is a separate thread. So if you are using a static resource you must handle the concurrency. In your case it seems that two datareaders are using the same connection. As your class is static, when the server is under heavy load it can happen that two requests will be using the same datacontext at the same time.

If you really need a static resource, you should use the lock statement to ensure that only one request at the same time access the resource.

Alejandro Martin
Well if the other object isnt released quickly ? still my app will get in to a problem right?.. i guess i must go with a non static resource for this >
Aneef