This is a problem I've had for over a year. I usually resolve it by marking all stored procs for recompilation.The following query call is generated by a web page to return summary values for a page footer:declare @P1 varchar(100)set @P1=NULLdeclare @P2 intset @P2=NULLdeclare @P3 intset @P3=NULLdeclare @P4 intset @P4=NULLdeclare @P5 varchar(100)set @P5=NULLdeclare @P6 intset @P6=NULLdeclare @P7 intset @P7=NULLdeclare @P8 intset @P8=NULLdeclare @P9 intset @P9=NULLdeclare @P10 intset @P10=NULLdeclare @P11 intset @P11=NULLdeclare @P12 intset @P12=NULLdeclare @P13 varchar(1000)set @P13=NULLexec dbo.AD_CourseStats 154409, 6732, @P1 output, @P2 output, @P3 output, @P4 output, @P5 output, @P6 output, @P7 output, @P8 output, @P9 output, @P10 output, @P11 output, @P12 output, @P13 outputselect @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, @P12, @P13
Normally, this query runs in under a second. The execution plan is great. Today, the bug is back and before I recompile the stored proc, I ran SQL profiler to get further information.Here's the query result from profiler when called from the web page via IIS:CPU 40000READS 684306WRITES 0DURATION 40000 The large number of reads and the resulting timeout indicates the stored procedure is not using an index to do the calculation. What is odd, is that the proc works fine when called from Query Analyzer. Read on...If I cut and paste the query into query analyzer, logged in as the same user the web uses, the query runs fine... here's the profiler data when the query is called from QA:CPU 234READS 884WRITES 0DURATION 483This is very repeatable, and is a major problem for the web / database performance. Fortunately, it is easily resolved by marking all stored procedures for recompilation.By the time you read this post, I'll have marked all stored procedures for recompilation, so I'll have to wait for the next occurance before performing any further tests.Sam