How do I check if a cursor is open or not? Because many times I am encountering the error 'Cursor already exists'. Please let me know how can I check whether a cursor is already in open status.
In fact I have closed as well as Deallocated it at the end (CLOSE ppm_cursor; DEALLOCATE ppm_cursor;) But Still i am getting the same error what could be the reason.
An application uses the cursor status property to determine how a cancel operation has affected a cursor. CS_CUR_STATUS is a command structure property and cannot be retrieved at the connection or context levels. Cursor properties are useful to gateway applications that send cursor information to clients.
@@FETCH_STATUS (Transact-SQL) This function returns the status of the last cursor FETCH statement issued against any cursor currently opened by the connection.
You can use the sp_cursor_list system stored procedure to get a list of cursors visible to the current connection, and sp_describe_cursor, sp_describe_cursor_columns, and sp_describe_cursor_tables to determine the characteristics of a cursor.
You can use the CURSOR_STATUS function to determine its state. For anyone else trying this with a cursor you yourself opened, and is maybe is left allocated because of error handling, you may have to change the global part to local .
You can use the CURSOR_STATUS function to determine its state.
IF CURSOR_STATUS('global','myCursor')>=-1 BEGIN DEALLOCATE myCursor END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With