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 2000 Forums
 SQL Server Administration (2000)
 Time out errors

Author  Topic 

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2004-07-22 : 03:10:30
There is this sp which is used in the webpage, it takes 3 seconds to execute from the
query analyser, but when it is called from the asp page it ends up in
"Microsoft OLE DB Provider for SQL Server error '80040e31'
Timeout expired "
I know it is an General error and there can be many reasons to it,
but on setting a profiler I found out that the sp is called only when the page timeouts,
meaning for some time there is no activity say for 5 -8 seconds and after that the sp is called and
the page timeouts...

just for the heck of it recompiled it ... and it worked for a couple of times then again it started giving me timeouts.
Now I have created the procedure with "WITH RECOMPILE" option, and
it works ..
can anyone explain why this might be happening?


He is a fool for five minutes who asks ,
but who does not ask remains a fool for life!



http://www.sqldude.4t.com

Kristen
Test

22859 Posts

Posted - 2004-07-22 : 03:24:44
Can you post the source code for the Procedure please, then we can see what its doing which might explain it.

Kristen
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2004-07-22 : 04:23:24
sure ... here is the code:

CREATE procedure dbo.rpt_pUStatistics
@ProvisionType int =Null,
@ReferalCode nvarchar(4) =NULL
with recompile
as
begin
declare @RoundTrip int
if @referalcode='0' set @referalcode=NULL
if @ProvisionType=0 set @provisionType=NULL


if (@referalcode is null) and (@provisionTYpe is null)
begin

select @roundTrip=count(distinct s.mailboxid)
from havsms..vw_vsms_sender s inner join havsms..vw_vsms_receiver r
on s.mailboxid = r.mailboxid
join userstoprovision up
on s.mailboxid=up.mailboxid

-----------+++++++
select count(userid)as'TotalUsers',count(PIN) as 'RegisteredUSers',isnull(@roundtrip,0) as 'RoundTrip'
from users u inner join userstoprovision up
on u.mailboxid=up.mailboxid



end
else
if (@provisionType is not null) and (@referalcode is not null)
begin
select @roundTrip=count(distinct s.mailboxid)
from havsms..vw_vsms_sender s inner join havsms..vw_vsms_receiver r
on s.mailboxid = r.mailboxid
join userstoprovision up
on s.mailboxid=up.mailboxid
where up.ProvisionedBy=@referalcode
and
up.provisionType=@provisionType

----------++++++++++

select count(userid)as'TotalUsers',count(PIN) as 'RegisteredUSers',isnull(@roundtrip,0) as 'RoundTrip'
from users u with (nolock ) inner join userstoprovision up
on u.mailboxid=up.mailboxid and
up.provisionedby=@referalCode and
provisionTYpe=@provisionType
end
else if (@provisionType is not null)
begin

select @RoundTrip=count(distinct s.mailboxid) from HAVSMS..vw_vsms_sender s inner join havsms..vw_vsms_receiver r
on r.mailboxid=s.Mailboxid
join userstoprovision up
on s.mailboxid=up.mailboxid
where up.provisionTYpe=@provisionType



select count(userid)as'TotalUsers',count(PIN) as 'RegisteredUSers',isnull(@roundtrip,0) as 'RoundTrip'
from users u inner join userstoprovision up
on u.mailboxid=up.mailboxid and
provisionTYpe=@provisionType


end


end







He is a fool for five minutes who asks ,
but who does not ask remains a fool for life!



http://www.sqldude.4t.com
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-07-22 : 04:57:07
I think the problem is probably the IF / ELSE.

These are mutually exclusive, so SQL will be making an Optimiser Plan for whichever scenario it gets the first time the SProc is called, and that Plan will be rubbish for the "other" scenario.

Either it is spotting this and recompiling (probably when it gets half way through the job!) or just using the lousy query plan.

You could change it to
IF (condition)
EXEC SProc_A
ELSE
EXEC SProc_B

so that SProc's A and B get indivually optimised.

Also, I wonder if

select @roundTrip=count(distinct s.mailboxid)
from havsms..vw_vsms_sender s inner join havsms..vw_vsms_receiver r
on s.mailboxid = r.mailboxid
join userstoprovision up
on s.mailboxid=up.mailboxid

would run fasted if coded something like:

select @roundTrip=count(s.mailboxid)
from havsms..vw_vsms_sender s
WHERE EXISTS (SELECT * FROM havsms..vw_vsms_receiver r
WHERE s.mailboxid = r.mailboxid)
AND EXISTS (SELECT * FROM userstoprovision up
WHERE s.mailboxid = up.mailboxid)

Kristen

Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2004-07-22 : 08:50:00
kristen thanks for the reply i'll check and let u know

He is a fool for five minutes who asks ,
but who does not ask remains a fool for life!



http://www.sqldude.4t.com
Go to Top of Page
   

- Advertisement -