Solved

Sql server lock cursor

Posted on 2016-10-25
13
39 Views
Last Modified: 2016-11-21
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
0
Comment
Question by:Alex
  • 6
  • 6
13 Comments
 
LVL 17

Accepted Solution

by:
Pawan Kumar Khowal earned 500 total points
Comment Utility
Try...10 should be your sessionid

SELECT c.session_id, c.properties, c.creation_time, c.is_open
, t.text
FROM sys.dm_exec_cursors (10) c
CROSS APPLY sys.dm_exec_sql_text (c.sql_handle) t

Open in new window

0
 

Author Comment

by:Alex
Comment Utility
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?
0
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
Comment Utility
So if you are sure nothing is happening in that session, why can't you go head and KILL the session itself.
0
 

Author Comment

by:Alex
Comment Utility
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.
0
 
LVL 12

Expert Comment

by:Dimitris
Comment Utility
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
0
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
Comment Utility
Hi Alex, Any luck with this?

Regards,
Pawan
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Alex
Comment Utility
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
0
 

Author Comment

by:Alex
Comment Utility
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?
0
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
Comment Utility
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 !
0
 

Author Comment

by:Alex
Comment Utility
0
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
Comment Utility
0
 

Author Comment

by:Alex
Comment Utility
I have already referred to the development team to approve.

Thank you
0
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
Comment Utility
Great ! Please inform me if you get reply from the development team.

Thank you !
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now