Solved

Sql server lock cursor

Posted on 2016-10-25
13
63 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
13 Comments
 
LVL 28

Accepted Solution

by:
Pawan Kumar earned 500 total points
ID: 41860055
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
ID: 41860442
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 28

Expert Comment

by:Pawan Kumar
ID: 41860450
So if you are sure nothing is happening in that session, why can't you go head and KILL the session itself.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:Alex
ID: 41860467
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
ID: 41862162
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 28

Expert Comment

by:Pawan Kumar
ID: 41871742
Hi Alex, Any luck with this?

Regards,
Pawan
0
 

Author Comment

by:Alex
ID: 41882842
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
ID: 41883078
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 28

Expert Comment

by:Pawan Kumar
ID: 41883263
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
ID: 41883499
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41883520
0
 

Author Comment

by:Alex
ID: 41883731
I have already referred to the development team to approve.

Thank you
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41883760
Great ! Please inform me if you get reply from the development team.

Thank you !
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Backup & Restore 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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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