Link to home
Start Free TrialLog in
Avatar of Support_38
Support_38

asked on

Sql server lock cursor

good evening

I'm blocking problem in sqlserver caused by cursor.

The head block I see is a fatch_api_cursor, the problem is that when I try to see the SQL code inside the cursor, it shows nothing and the status is like sleeping.

any idea how I can detect what is inside the cursor?

I've tried to dmv sys.dm_exec cursors but does not provide any information.

I have to kill the process to release the locks.

thank's
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Support_38
Support_38

ASKER

hello,

Unfortunately I had tried it, but does not provide any information when the status of the process is sleeping.

It shows information only when the status of the process is runnable which is not my case.

Any other ideas?
So if you are sure nothing is happening in that session, why can't you go head and KILL the session itself.
I have a lock chain, when I check the head block and see what is running, get running fetch_api_cursor ...

When you check the DMV sys.dm_exec_cursors does not provide any information for this process.

Some processes that are sometimes head block to bring the information below:

IF @@ TRANCOUNT> 0 COMMIT TRAN

But the vast majority, does not provide any information.
could it be that the cursor is in an endless loop? (@@FETCH_STATUS issue)

if you see the process running it means that it's waiting for something
Try to change the CURSOR to LOCAL (DECLARE rst CURSOR LOCAL)
are you closing the cursor (CLOSE rst and DEALLOCATE rst )?
and if you are not updating anything with the cursor and you are just reading data make it also a FAST_FORWARD cursor (it means forward only, readonly)

If you could provide some code lines it would be easier
Hi Alex, Any luck with this?

Regards,
Pawan
Hello,

Unfortunately it still could not detect which sql statement is running inside the cursor, even using the sys.dm_exec_cursors dmv.

The process status that is as headblock is sleeping
Based on the information in this link, it is very similar to the scenario that is occurring in the environment.

https://blogs.msdn.microsoft.com/psssql/2008/04/21/how-it-works-what-is-a-sleepinga-awaiting-command-session/

Can the set xact_abort option help?
XACT_ABORT informs SQL Server to rollback the entire transaction and abort the batch when a run-time error occurs.

Actually the link you gave is not working. :)

Try XACT_ABORT it works. Also if you want the hard way we can use KILL sessionId to kill the session. Although it is not recommended.

Hope it helps !
I have already referred to the development team to approve.

Thank you
Great ! Please inform me if you get reply from the development team.

Thank you !