Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sql server lock cursor

Posted on 2016-10-25
13
Medium Priority
?
82 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:Support_38
  • 6
  • 6
13 Comments
 
LVL 35

Accepted Solution

by:
Pawan Kumar earned 2000 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:Support_38
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 35

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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:Support_38
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 35

Expert Comment

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

Regards,
Pawan
0
 

Author Comment

by:Support_38
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:Support_38
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 35

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
 
LVL 35

Expert Comment

by:Pawan Kumar
ID: 41883520
0
 

Author Comment

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

Thank you
0
 
LVL 35

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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.
In this article I will describe the Copy Database Wizard 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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

885 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