Re: SQL server procedure gets cut off before completion
Hi BG,
I apologise for not replying earlier - I had problems with Netscape. I don't think I should post a copy of my stored procedure on the bulletin board because it is over 3000 lines long! I have given a brief description of the pseudocode below:
CREATE PROCEDURE Attend
(parameters)
AS
DECLARE
(variable names)
CREATE table #tblAttend
( field1, ... fieldN)
CREATE unique index idx_attend_key on #tblAttend(field1)
/*The select statement immediately below is repeated for 5 more temp tables, #temptableB - F*/
SELECT distinct (field names)
into
#temptableA
from
table1, ... tableN
where
(selection criteria)
DECLARE cursAttend cursor static for
SELECT #tblAttend.field1, ... fieldN
from #tblAttend
OPEN cursAttend
FETCH next from cursAttend into @variable1, ... @variableN
WHILE (@@fetch_status =0)
BEGIN
-- Debug, show field value.
PRINT 'Field1 is: ' + @variable1
FETCH next from cursAttend into @variable1, ... @variableN
END
CLOSE cursAttend
DEALLOCATE cursAttend
There is more code in the stored procedure, but
the part that gets cut off is the WHILE loop just above (it cycles halfway through the loop then just stops).
Furthermore, the cutoff-point seems arbitrary - sometimes the program gets a bit further than halfway, sometimes not so far. This made me think the problem was a timeout. But when I purposely introduced a 10 second-delay in the program after the variable declarations, then the VB front end (that calls the stored procedure) waited for those 10 seconds before stopping in more or less the same place (in the middle of the WHILE loop).
Any ideas you have are welcome!
SQL Server stored procedure gets cut off before completion
Just in case anyone was wondering, I solved the problem - the stored procedure was getting cut off when called from VB because of all the debug statements left inside it! It was due to SELECT * FROM statements and (to a lesser extent) PRINT statements - which apparently slow down SQL server considerably.