{"title":"Troubleshooting: Using Event Viewer to monitor long-running SQL queries in Business Central","url":"https://jonas-paprotka.de/docs/dev-itpro/administration/troubleshoot-long-running-queries-using-event-log/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/troubleshoot-long-running-queries-using-event-log, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/troubleshoot-long-running-queries-using-event-log","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Use Windows Event Viewer to investigate long-running SQL queries in Business Central and inspect SQL statements and AL call stacks for optimization.","date":"2026-11-17","meta":{"topic":"troubleshooting-general"},"outline":[{"level":1,"title":"Troubleshooting: Using Event Viewer to monitor long-running SQL queries in Business Central","slug":"troubleshooting-using-event-viewer-to-monitor-long-running-sql-queries-in-business-central","at":0,"chars":4062},{"level":2,"title":"Monitor long-running queries","slug":"monitor-long-running-queries","at":268,"chars":3191},{"level":3,"title":"Using the AL call stack","slug":"using-the-al-call-stack","at":1309,"chars":2150},{"level":2,"title":"Related information","slug":"related-information","at":3459,"chars":603}],"text":"# Troubleshooting: Using Event Viewer to monitor long-running SQL queries in Business Central\nThis article shows how you can monitor long-running SQL queries in Event Viewer. You use the information to determine which SQL queries are good candidates for optimization.\n## Monitor long-running queries\nIdentifying long-running SQL queries can be a good starting point when doing a performance analysis. Open Event Viewer and go to Windows Logs > Application. If logging to the Application log is disabled, use Applications and Services Logs > Microsoft > DynamicsNAV > Common > Admin instead.\n> NOTE\n> Successful SQL queries that meet or exceed the configured threshold are logged as warnings.\nThe default value of the SqlLongRunningThreshold setting is 750 milliseconds. For successful queries that meet or exceed the threshold, you'll see the message: \"Action completed successfully, but it took longer than the given threshold.\"\nTo meet performance expectations in production, you can set the threshold to a different value. You can set the threshold without restarting the server instance. See Monitoring Long Running SQL Queries using the Event Log<monitor-long-running-sql-queries-event-log>.\n![Screenshot of an Event Viewer warning for a SQL query that exceeded the configured execution time threshold.]\n### Using the AL call stack\nLong-running queries that involve the explicit execution of AL code can include an AL call stack in the event log. Long-running queries that aren't the result of explicit AL code won't include an AL call stack. For example:\n GetPage calls that load data into the UI.\n Calls to triggers that don't include any code. These calls won't include an AL call stack because no AL code is run.\nLooking at the AL call stack can help you identify what caused the delay. The generated SQL statement is listed in the Statement field, and the AL call stack is listed in the `AL CallStack` field. The following log example shows which AL method generated a slow-running query.\n```text\nServer instance: BC\nCategory: Sql\nClientSessionId: aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb\nClientActivityId: aaaa0000-bb11-2222-33cc-444444dddddd\nServerSessionUniqueId: bbbbbbbb-1111-2222-3333-cccccccccccc\nServerActivityId: bbbb1111-cc22-3333-44dd-555555eeeeee\nEventTime: 06/08/2018 08:10:15\nMessage Action completed successfully, but it took longer than the given threshold.\n  Execution time: 33 ms\n  Threshold: 10 ms\n  Message: Long running SQL statement\n  Task ID: 3\n  Connection ID: 2\n  Database Name: BCDB\n  Statement: SELECT \"2161\".\"timestamp\",\"2161\".\"User\",\"2161\".\"Default Execute Time\",\"2161\".\"Current Job Queue Entry\" FROM \"SQLDATABASE\".dbo.\"CRONUS International Ltd_$Calendar Event User Config_\" \"2161\"  WITH(UPDLOCK)  WHERE (\"2161\".\"User\"=@0) OPTION(OPTIMIZE FOR UNKNOWN)\n    AppObjectType: CodeUnit\n  AppObjectId: 2160\n  AL CallStack: \"Calendar Event Mangement\"(CodeUnit 2160).GetCalendarEventUserConfiguration line 2\n\"Calendar Event Mangement\"(CodeUnit 2160).FindJobQueue line 1\n\"Calendar Event Mangement\"(CodeUnit 2160).FindOrCreateJobQueue line 1\n\"Calendar Event Mangement\"(CodeUnit 2160).CreateOrUpdateJobQueueEntry line 1\n\"Calendar Event\"(Table 2160).Schedule line 12\n\"Calendar Event\"(Table 2160).OnInsert(Trigger) line 1\n\"Calendar Event Mangement\"(CodeUnit 2160).CreateCalendarEventForCodeunit line 6\n\"Create Telemetry Cal. Events\"(CodeUnit 1352).OnRun(Trigger) line 5\n\nProcessId: 15280\nTag: 000007L\nThreadId: 10\nCounterInformation:\n```\n## Related information\nTroubleshooting: Analyzing Long Running SQL Queries Involving FlowFields by Disabling SmartSQL<troubleshooting-queries-involving-flowfields-by-disabling-smartsql>\nMonitoring Long Running SQL Queries using the Event Log<monitor-long-running-sql-queries-event-log>\ntools-monitor-performance-counters-and-events\nBusiness Central Server Administration Tool<administration-tool>\nTroubleshooting: Using Query Store to Monitor Query Performance in Business Central<troubleshoot-query-performance-using-query-store>\nhttps://learn.microsoft.com/sql/relational-databases/sql-trace/sql-trace"}