May 12, 2004 at 11:48 am
I have a stored procedure that will start timing out if run through our app (C++ Middle Tier using ADO), but when run in Query Analyzer it runs in under 2 seconds. Stop and Start SQL/Server and then the stored procedure runs in under two seconds in the app for a period of time (hours) and then starts timing out again. All the time it runs in Query Analyzer in under two seconds.
Obviously I can't keep stopping and starting SQL/Server everytime this happens. Any clues as to what's going on would be appreciated. I'm stumped!
May 13, 2004 at 4:24 am
I have had similar problems. In one instance, some of my permissions were off. In the others, I had to move away from teh SP and put that code into the app itself.
May 13, 2004 at 6:36 am
Thanks.
Here is some new info. It happened again this morning and instead of stopping and starting SQL/Server, I did an Alter on the stored proc to refresh it and it started working in the App again. This still is not a viable solution, but maybe sheds some more light as to what the actual problem is.
May 13, 2004 at 6:51 am
Are you running the stored procedure with the same arguments and the same login for both you application and query analyzer? Did you copy exactly what was returned from the profiler into query analyzer under the same account? Have you tried a tiny program that only invokes the stored procedure from a script or small application? Are any locks occuring at the same time? Are you or ADO using cursors to grab the data? The only reason query analyzer should give you faster results is that you are waiting on I/O from your application. There is probably more to your puzzle than you believe.
May 13, 2004 at 6:55 am
You mentioned before that the refresh of the stored procedure helped. Try setting your stored procedure to compile every time you run it.
May 13, 2004 at 7:08 am
Stored procedure is being run with the same arguments in both App and Query Analyzer. Although the App times out with any arguments. We have tried a test VB app that uses the same COM object running in COM+, it also times out. Will try a test script that calls the stored proc directly next time, thanks for the idea. Also, will try COM object running outside COM+. No cursors are involved.
May 13, 2004 at 8:00 am
We have done a couple of different things to work around this behavior. You can force the proc to recompile like:
ALTER PROCEDURE [usp_testRecompile]
@begin bigint,
@end bigint,
with recompile
as
set nocount on
SELECT column1, column2, ....
Or you can issue these 2 commands at anytime which will have the same effect:
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
May 14, 2004 at 12:12 am
Are you using a command object with parameters to address the storedproc ?
Is the commandtype "storedproc" ?
Are the parameters defined with _exactly_ the same db-column-type (datatype, length, precision, scale, ...) ?
Is your stored procedure being reused ? (master..syscacheobjects)
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
May 14, 2004 at 6:15 am
First when it is timing out have you tested QA at that moment?
If so what was the outcome?
altering and bouncing seem to fix temporarily so I believe the answer lies in you com object.
Would you be willing to send me the VB com object or the C++ object (of course changed for security, just need the code to see maybe what is going on)? Or post it here if all code can be posted easily, again remember to alter security info such as server, login name, and password.
May 14, 2004 at 6:30 am
Hi there,
Just observing this stream, because I had the same problem a couple of times and I have found no solution.
This also happens when there is no com envolved. When a Procedure is complex enough, the server can't decide on the correct execution plan anymore. This got to do with the statistics vs. the estimated cost per different execution plan. The server seems to get in a loop at one point trying to decide on the optimal plan.
This is partly the reason Microsoft gives, however, short from the mentioned solutions, I don't know of any solution.
For me what always helped was to declare the same procedure local variables and set those to the parameters and then use these local variables in the SP. This seems to force a recompile, but not completly
So, please if anybody got a good suggestion... post it please!!
Greetz, Robert.
May 14, 2004 at 6:50 am
We ran it via a VBScript just using ADO to connect to the database. Therefore eliminating the possibility of it being our COM object. It still timed out.
I noticed that when it is failing, ADO and Query Analyzer report different execution plans for the failing query in the stored proc. After recompile of the stored proc. ADO goes back to the execution plan that Query Analyzer is using and that it had been using up until it gets into its failed state.
So if anybody has an answer as to why all of the sudden ADO would start using an execution plan that is different than the one it has been using and is different to the one that when the stored proc is run via Query Analyzer it uses, let me know. Because I believe therein lies the solution to this problem.
One thing I might try is using index hints in the proc to always force the good execution plan and not let the optimizer choose the plan.
Also, the query that it times out on in the stored proc is not a complicated query.
May 14, 2004 at 1:15 pm
I do have similar problem with complex SQL within SP. Did you check when this problem occured, is your execution plan same as when it behave ? I had discussed this with some senior engineer, they believed this may cause by the way Microsoft assemble the statistics. As most of you know, most of the time SQL only assemble the statistics using 10% of the 'sample' data. If somehow, if the data you populate is beyond their 'sample' algorithm, the SQL may actually pick the wrong query plan and hence cause the same SP slow down.
We come up with few ways, they all seems fix the problem,
1. Our solution is to put 'keep plan' option in the SP (using alter). It works for us.
2. run db-reindex on all the tables involved with the SP/SQL everyday. Which also seems resolve this issue.
May 17, 2004 at 4:40 am
May 18, 2004 at 12:25 am
The only way of explaining why all of a sudden your proc is using an other execution plan is that is has been explicitly recompiled or that is has been thrown out of the procedure cache (because of least recent used) and later on used again and therefor had to be compiled again.
At compilation time statistics must have been so that the other access was prefered by sqlserver.
Before tweaking with hints, try to optimize your query !
- Are you telling sqlserver _everything_ you know about the query ?
- Try to explain why sqlserver chooses the "wrong" plan. (what's going on with the statistics ?)
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
May 18, 2004 at 12:57 am
I've tried running some procedures from VB and from Query analyzer. No actions where taken on the database and no time (hardly any) was between both executions. Still the one from query analyzer finnished in normal times and the one from VB never finished and timed out. Actually this is probably linked to the fact that I've had it happen that running the query directly did finish in query analyzer and running the SP in query analyzer didn't..
It seems to be related to the execution plan and the one is chosen at run-time. However, this seems strange to me, since the execution-plan is bound to the SP and not to the calling-client software.
Viewing 15 posts - 1 through 15 (of 19 total)
You must be logged in to reply to this topic. Login to reply