{"title":"Monitoring and analyzing long-running SQL queries","url":"https://jonas-paprotka.de/docs/dev-itpro/administration/monitor-long-running-sql-queries-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/monitor-long-running-sql-queries-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/monitor-long-running-sql-queries-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":"Monitor long-running SQL queries from Business Central Server in the Windows event log and Application Insights to investigate slow database operations.","date":"2026-11-17","meta":{"topic":"how-to"},"outline":[{"level":1,"title":"Monitoring and analyzing long-running SQL queries","slug":"monitoring-and-analyzing-long-running-sql-queries","at":0,"chars":3127},{"level":2,"title":"Defining the long-running SQL query threshold","slug":"defining-the-long-running-sql-query-threshold","at":520,"chars":1563},{"level":2,"title":"Monitor and analyze data","slug":"monitor-and-analyze-data","at":2083,"chars":357},{"level":2,"title":"Related information","slug":"related-information","at":2440,"chars":687}],"text":"# Monitoring and analyzing long-running SQL queries\nMicrosoft Dynamics NAV 2017 was the first version that allows long running SQL queries to be logged to the Windows Event Log. The queries are logged when the application communicates with the database and the call to the database takes too long. Starting in Business Central 2019 release wave 2, long running queries can also be emitted as telemetry to Microsoft Azure Application Insights. Using Application Insights requires that you first enable it on your tenant.\n## Defining the long-running SQL query threshold\nThe time logged when a SQL query runs is the time spent on the called database as seen from the server. There are multiple reasons that can cause a delay. For example, a delay happens when the database waits for a lock to release. Or it runs an operation that's missing indexes.\nThe Business Central Server configuration setting SqlLongRunningThreshold controls when a successful SQL query is logged as long-running in the Windows event log. In Business Central version 29, the default value is 750 milliseconds (ms). A query that takes at least the threshold is logged with a warning.\nThe separate setting SqlLongRunningThresholdForApplicationInsights controls the threshold for Application Insights telemetry. Its default value is also 750 ms. Changing one setting doesn't change the other.\nLearn more about setting SqlLongRunningThreshold by using the Set-NAVServerConfiguration cmdlet<https://learn.microsoft.com/powershell/module/microsoft.dynamics.nav.management/set-navserverconfiguration> in Configuring Business Central Server<configure-server-instance>.\nThe cmdlet includes the `-ApplyTo Memory` parameter that enables you to change the setting without doing a server restart. For example, to change the event-log threshold dynamically to 2000 ms, run the Business Central Administration Shell as Administrator and then type the following PowerShell cmdlet:\n```powershell\nSet-NAVServerConfiguration -ServerInstance <ServerInstanceName> -KeyName SqlLongRunningThreshold -KeyValue 2000 -ApplyTo Memory\n```\n## Monitor and analyze data\nLearn more about using the Windows event log in Troubleshooting: Using the Event Viewer to Monitor Long Running SQL Queries<troubleshoot-long-running-queries-using-event-log>.\nLearn more about setting up and using Application Insights in Enabling Application Insights for Tenant Telemetry<telemetry-enable-application-insights>.\n## Related information\nTroubleshooting: Using the Event Log to Monitor Long Running SQL Queries<troubleshoot-long-running-queries-using-event-log>\nTroubleshooting: Analyzing Long Running SQL Queries Involving FlowFields by Disabling SmartSQL<troubleshooting-queries-involving-flowfields-by-disabling-smartsql>\nMonitoring and Analyzing Telemetry<telemetry-overview>\nhttps://learn.microsoft.com/powershell/module/microsoft.dynamics.nav.management/set-navserverconfiguration\ntools-monitor-performance-counters-and-events\nMonitoring Business Central Server Using Performance Counters<monitor-server-using-performance-counters>\nMonitoring Business Central Server Events<monitor-server-events>"}