Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop Endless Loop

Status
Not open for further replies.

grnzbra

Programmer
Mar 12, 2002
1,273
US
I have a stored procedure, in SQL Server 2012, containing a cursor that doesn't have the second FETCH statement, so @@FETCH_STATUS is always zero and it keeps running and running and running. Is there any command that can be issued that will tell it to STOP NOW? I've tried canceling the procedure and there is a notice at the bottom of the query window that says "Cancelling query..." but nothing seems to be happening.
 
Why this loop does not have second FETCH?
Use BREAK to exit the loop.

Borislav Borissov
VFP9 SP2, SQL Server
 
Because the idiot (me) forgot to put it in.

But it looks like the BREAK would have to already be in the code.
 
So, it looks like the server is stuck now and you have to stop and restart the SQL Server Service to make this stop.

Even if the service is still responsive I don't know a way to stop a certain blocking SPID from outside.

You can list running processes via exec of sp_who and sp_who2, for a short explanation of SPID also see
Bye, Olaf.
 
Oh, it's simpler than I thought, knowing which SPID is the one executing your endless running loop you can use the KILL command:

If you can't identify it might help to store the sp_who2 result, start the proc once more and see what new SPID is added, when you redo sp_who2 and compare previous and current result. Comparing old and new sp_who2 records and may identify which one is new and which of the old ones is similar and belongs to the initial call.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top