code_junkie

Is there any way to get a list of open/allocated cursors in SQL server?

Nov 12th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. CREATE PROCEDURE dbo.p_cleanUpCursor @cursorName varchar(255) AS
  2. BEGIN
  3.  
  4. DECLARE @cursorStatus int
  5. SET @cursorStatus = (SELECT cursor_status('global',@cursorName))
  6.  
  7. DECLARE @sql varchar(255)
  8. SET @sql = ''
  9.  
  10. IF @cursorStatus > 0
  11. SET @sql = 'CLOSE '+@cursorName
  12.  
  13. IF @cursorStatus > -3
  14. SET @sql = @sql+' DEALLOCATE '+@cursorName
  15.  
  16. IF @sql <> ''
  17. exec(@sql)
  18.  
  19. END
Add Comment
Please, Sign In to add comment