Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Complex, unexplainable timeout of SP?

Author  Topic 

djorre
Yak Posting Veteran

94 Posts

Posted - 2010-11-29 : 12:15:17
Hello,

This is a very strange problem I am having with a query.
It looks like this:

SP_Websetfilters
@reportId int,
@FilterNumber int,
@StartDate datetime,
@EndDate datetime,
@DropDownList1 varchar(1000),
@DropDownList2 varchar(1000)
...
-- Test table to verify input variables from web application
Insert into TestSetFilters VALUES
(@reportID, getdate(), @FilterNumber, @StartDate, @EndDate, @DropDownList1, @DropdownList2)
Insert into TestSetFilters VALUES
(@reportID, getdate(), @FilterNumber, null, null, SUSER_NAME(), HOST_NAME())
...
<< continuing stored procedure using linked server historian etc).>>




When I run this SP from the management console, it logs this into testsetfilters table (actually these are just all input variables I can think of):

953797 17 2010-11-29 19:06:52.823 6 NULL NULL ODRMGS\pradmin RPT1
953796 17 2010-11-29 19:06:52.823 6 2010-11-01 00:00:00.000 2010-11-30 00:00:00.000 1 empty

And it has a result query.


But when I run this query from a website, that has the same user impersonation as above, it logs exactly the same as variables:


952897 17 2010-11-29 19:06:46.073 6 NULL NULL ORDMGS\pradmin RPT1
952896 17 2010-11-29 19:06:46.073 6 2010-11-01 00:00:00.000 2010-11-30 00:00:00.000 1 empty

But it does TIMEOUT and I get no data.

The problem is not in the website because I also log the retrieved query into a table, and the SP running in SMT gets the data but using the asp website the table is not filled. So the timeout is in sql.

How can this be possible? I think I run this SP twice with exactly the same parameters and user, but one always timeouts and the other runs in 4 seconds.

Please help me this is really getting on my nerves. After some rebooting etc the problem can sometimes be solved out of nowhere. But it always comes back after a while.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-29 : 13:05:03
Your connection settings have to be identical in order to duplicate what the web site is doing. It's very likely that your SSMS connection settings are different than the web site connection settings. If even just one setting is different, you can get a different execution plan than the web site. And the web site could have a bad plan, and yours could have a good plan.

Have you tried recompiling the stored procedure in case it's a bad plan? Have you tried checking the web site's plan via SQL Profiler and comparing it to your plan from SSMS? Have you checked blocking?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

djorre
Yak Posting Veteran

94 Posts

Posted - 2010-11-30 : 04:03:26
Hello,

I am not known with execution plans. I can read about it though... but why would an execution plan be different? Are the SSMS connection settings also something that I can log in a table so that I can see they are different? Indeed I think it has to do with the execution plan because sometimes if I change the order of things in the SP it works for a while. How can I make sure they both use the good execution plan?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-30 : 12:30:39
The execution plans can be different because the settings different. SQL Server isn't going to treat them as the same.

I'm sure you could somehow grab the settings and put them into a table, but I don't have a handy script for that or any clue how'd you do it. You can view the connection settings in a trace though.

You can try index hints, but I wouldn't go that route until you've diagnosed the problem. Check the execution plans and let us know.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

djorre
Yak Posting Veteran

94 Posts

Posted - 2010-12-01 : 05:15:23
The computer was rebooted and it the problem is gone again. Very frustrating in a certain way.
So I need to set up a trace to diagnose this problem? Can I see the execution plans in the trace?
Thank you!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-01 : 10:44:48
Yes you can see the execution plans in the trace. A trace is a very good way to capture this problem.

Rebooting the computer likely fixed the problem because you had a bad plan in cache. A simple recompiling of the stored procedure or running DBCC FREEPROCCACHE would have fixed it instead of the reboot. Rebooting should be done as an absolute last measure as it requires downtime, downtime which most people can't afford.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

djorre
Yak Posting Veteran

94 Posts

Posted - 2010-12-08 : 10:18:41
Thank you,

Now the problem is back but it's different, when a sql user tries to access the linked server it loads eternally, when a windows admin user tries it, it works. While the authentication in the linked server is always mapped to that windows user. I set up a trace but the only thing I can see there is the confirmation that for the sql user there is no answer coming. The other side (historian server) does not notice an incoming connection. Maybe that has to do with dcom settings I don't know, but it is different from the problem above. Thank you.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-08 : 12:06:20
I don't have a clue about that one. Perhaps someone else can help. If it were me, I'd open a case with Microsoft.

I'm in SQL Server training this week with two experts, and the answer to how to get the user connection settings was brought up yesterday. Here's the answer:

For your current session, you can use DBCC USEROPTIONS.

For all users sessions, use a DMV: sys.dm_exec_sessions.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -