Executed as user NT AUTHORITY5cSYSTEM A cursor with the name does not exist

Executed as user NT AUTHORITY5cSYSTEM A cursor with the name does not exist

Executed as user: NT AUTHORITY\SYSTEM. A cursor with the name does not exist

Sense is you are deallocating cursor which was not initialised yet.

Exception in your procedure was thrown prior to execution of create cursor.


Lets reproduce this error

scenario: You have created stored procedure and it uses try catch block or transaction mode to commit or roll back
based on exception.

e.g.

Begin Transaction tran1 
 
-- create temporary table schema

DECLARE Cursor_Name CURSOR  for FOR select_statement

-- cursor will process the rows and push those rows into temporary table.

 commit transaction tran1

 begin catch
 
 deallocate  Cursor_Name   -- here you have error while deallocating the cursor which was not created

 Rollback transaction tran1


Resolution check your table scheama and its data type. or find appropriate error.



Global:- cursor is global to the connection. The GLOBAL cursor will be implicitly deallocated at disconnect.

 Cursor optimization tips

1. First tip. Avoid cursors whenever possible

2. close cursor when its result set is not needed.

3. deallocate cursor after use

4. try to reduce number of records to process using cursor

5. use readonly cursor instead of update cursor.

6. use Fast_Forward cursors whenever possible.


Tags: