|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Cursor will not die!
I have a problem where a stored procedure will only work once per session. If I create a new query mgr window it will work again - but only once. Same deal when called from an ASP page - will work once per session.
The procedure has a cursor & a @@FETCH_STATUS while loop. At the end of the loop the cursor is closed and deallocated. I did a test to return the FETCH_STATUS variable and it comes back -1 and the loop does not run - so no recordset gets created unless it's the first time the procedure is run. Any clues on why this is happening? and how to really kill the cursor at the end of the procedure run thru? Many Thanks ! |
|
#2
|
||||
|
||||
|
post the code for the cursor.
|
|
#3
|
|||
|
|||
|
Thanks for replying. It's the strangest thing (well to me anyway) - the code works exactly as I want - problem is it will only run once. Any further calls from the same session = an empty recordset. It's because the cursor remains at the end, even though it's been closed and deallocated.
Code:
CREATE PROCEDURE dbo.getphotosbypage @UserID int, AS DECLARE @pagecounter int, @monthcounter int, @priorDate datetime, @photoID int, @comments varchar(500), @nextdate datetime, CREATE TABLE photos_temp (monthcount int, photoID int, comments varchar(500), dateuploaded datetime) set @monthcounter = 1 DECLARE photos_cursor CURSOR FOR SELECT photoID,comments,dateuploaded FROM Photos WHERE UserID = @UserID ORDER BY Dateuploaded OPEN photos_cursor WHILE @@FETCH_STATUS = 0 BEGIN FETCH NEXT FROM photos_cursor INTO @PhotoID, @comments, @Nextdate if datepart(mm,@nextdate) <> datepart(mm,@priordate) OR datepart(yy,@nextdate) <> datepart(yy, @priordate) BEGIN SET @monthcounter = @monthcounter + 1 END If @priorID <> @photoID BEGIN insert into photos_temp (monthcount,photoID,comments,dateuploaded) values (@monthcounter, @photoID, @comments, @Nextdate) END SET @priordate = @Nextdate SET @priorID = @photoID END select * from photos_temp SET @photoID = null SET @comments = null SET @nextdate = null DROP TABLE photos_temp CLOSE photos_cursor DEALLOCATE photos_cursor GO Last edited by Memnoch : January 9th, 2005 at 11:13 AM. |
|
#4
|
|||
|
|||
|
my problem was solved.
|
|
#5
|
||||
|
||||
|
how did you solve the problem?
|
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Cursor will not die! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|