Solved

Sql server lock cursor

Posted on 2016-10-25
13
72 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
[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 29

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: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 29

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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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 29

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 29

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 29

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 29

Expert Comment

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

Thank you !
0

Featured Post

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.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

622 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