web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

What is the best way to see the query behind a cursor in Top SQL Reports coming from SQL Server

(0) ShareShare
ReportReport
Posted on by

I have a SQL report coming from a 3rd party application, reporting that the following function has long waits. I have also seen something similar from Dynamics AX X++ SQL (Application) Logging. What is the best way for me to find the SQL query behind this cursor?

FETCH API_CURSOR0000000000688C29

Thank you,

John

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Denis Macchinetti Profile Picture
    16,444 on at

    Hi John

    The API cursors are used to fetch data rows from the server.

    Take a look to this post www.sqlskills.com/.../hunting-down-the-origins-of-fetch-api_cursor-and-sp_cursorfetch

    You have to run the below query and indicate the SQL Session ID

    SELECT c.session_id, c.properties, c.creation_time, c.is_open, t.text

    FROM sys.dm_exec_cursors (SESSION_ID) c

    CROSS APPLY sys.dm_exec_sql_text (c.sql_handle) t

    Finally, check the expensive queries on SQL Activity Monitor. Maybe it help you.

  • Suggested answer
    Community Member Profile Picture
    on at

    If you want to check long running queries in AX, you may enable SQL statement trace log under user options >> SQL >> SQL Trace.

    Mention the long queries threshold in milli seconds and enable Table(database).

    All the long running SQL queries beyong the mentioned threshold will be captured in the SQL statement trace log under System Admin >> Inquiries >> Database >> SQL Statement trace log.

  • Denis Macchinetti Profile Picture
    16,444 on at

    Hi Manish

    John is talking about a SSRS report coming from a 3rd party Application so, the feature that you mention doens't help.

  • Community Member Profile Picture
    on at

    yes

    I understood it wrongly :-)

  • Denis Macchinetti Profile Picture
    16,444 on at

    No issue -))

    "Here" we are in many with different knowledge.

    So, it's better clarify according the Topic.

    That's it!

  • John_Castro Profile Picture
    on at

    Thank you, i fell across the same article and found it very useful. In addition to the mentioned query, the following shows all active cursors.

    SELECT c.session_id, es.program_name, es.login_name, es.host_name, DB_NAME(es.database_id) AS DatabaseName, c.properties, c.creation_time, c.is_open, t.text

    FROM sys.dm_exec_cursors (0) c

    LEFT JOIN sys.dm_exec_sessions AS es ON c.session_id = es.session_id

    CROSS APPLY sys.dm_exec_sql_text (c.sql_handle) t

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans