开发者

LINQ to SQL - There is already an open data reader associated with this command whic must be closed first

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 pa开发者_JAVA技巧ssed them to the static methods every time i call them. is what i did was correct, will that resolve this issue ?/


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜