Link to home
Start Free TrialLog in
Avatar of AddOnsInc
AddOnsInc

asked on

How do I determine query executing in sp_cursorfetch ?

We have a SQL Server 2005 database where from time to time locks are happening that we have not been able to identify.

There is a lock being taken sporadically - output from Activity Monitor and sp_who2 identifies the PID that is blocking everything else.

We turned on Profiler and for that PID we can see that it's executing sp_cursorfetch.  We don't know that SQL that's executing in that cursor and would like to know if there's someway to find out.

Oracle has a couple of dynamic views v$sql and v$sqlarea that can show you the parsed SQL stored in memory.  Does SQL Server offer something similar so that we can determine what's executing this cursor that seems to be randomly taking control of our DB ?
ASKER CERTIFIED SOLUTION
Avatar of jorge_toriz
jorge_toriz
Flag of Mexico 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 AddOnsInc
AddOnsInc

ASKER

That was enough to get me what I needed.

We discovered this:

We found the blocking PID from Activity Monitor and stuck it into the query below:

select sql_handle from sys.dm_exec_cursors(<pid>);

Then:

select text from sys.dm_exec_sql_text (<sql_handle>).

Thanks!
The solution as posted gave a pointer in the right direction, we had to work out the rest ourselves.  So, a B for the pointer that wasn't quite the complete solution in and of itself.