Every few months a few select pages of a website will start responding with
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
I ran SQL Server Profiler to see where the database is getting hung up. It's on a specific stored procedure. So I took the stored procedure call and ran it through Management Studio. Returns a few thousand rows in under a second.
Opening up the procedure, I see it's just a simple select statement. If I take the select statement out and run it in a new query window, Management Studio will hang.
So I start running it in pieces, and find the line that's causing the query to hang
and GetDate() between EffectiveDate and ISNULL(ExpiryDate, @CurrentDate)
GetDate()
is supposed to be @CurrentDate
anyways, so if I switch it, it'll run fine. Why does this even matter though? As I understand, GetDate
should not be an expensive call. I understand IsNull
is, but that shouldn't matter either, as it can handle the query fine if I just swap out GetDate with CurrentDate.
Am I correct in assuming getdate
is causing this query to hang intermittently? How/why would it do that?
A bit of background, as I said this error has popped up before, on March 23rd, July 27th, October 25th and now November 21st. It always seems to happen near the end of the month. I've been assured nothing is going on during this time (scheduled tasks, maintenance, etc.)
This is on a production server, so I haven't been able to actually take the time to debug the problem. As soon as the site goes down, it has to be brought back up. I know how to fix it, I just need to force a recompile on the stored procedure, but does anyone have any idea what could be causing this?
The SQL Server also has another UAT database, the same procedure will hang on that database as well. But other stored procedures that have that exact same line of code run fine on both databases.
Edit: I had to put the website back up, so I recompiled the stored procedure. The site now runs fine. The query still doesn't run on it's own though.