Im having an ongoing issue with my site, it basically times out and dies. I have gotten to the point now where I have had to set the application pool to auto recycle every 5 minutes, but even that has failed as I’ve just got back from work and my email inbox is full of 4000 emails all with the same error.
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
This morning I tried a test where I disabled pooling on the connection string, this also didn’t work.
Now I’m thinking that perhaps this isn’t an issue with the leaky connections, I’ve been through all that before, I think it maybe something to do with the static properties that are core to my site
Here is one of them
public static List<Member> AllMembers
{
get
{
if (HttpRuntime.Cache["Members"] != null)
{
return (List<Member>)HttpRuntime.Cache["Members"];
}
else
{
GetAllMembers();
return (List<Member>)HttpRuntime.Cache["Members"];
}
}
}
This is called whenever I want a list of the members, you can see that if its null it populates the cache, which will use the database, and if it’s not null then it will return the cache object. I also have SQLCacheDependancy too which will clear these cache objects so it will again populate them. So this property gets called ALOT.
Now this is a web application and as my traffic has increased its dyeing all the time,
Could my properties be the cause?
Any help is most appreciated
Truegilly
Assuming you are disposing of everything correctly, I have an alternative explaination:
If the cache is empty/expired and multiple pages try to call
AllMembersat the same time, then each page may will end up callingGetAllMembers()simultaneously, slowing down the database query. This could start a vicious cycle if the calls start timing out.You could place a
lockaround your code, so only one database query per property can be made. Here is how I might set it up: