diff --git a/Lite/Controls/ServerTab.xaml.cs b/Lite/Controls/ServerTab.xaml.cs index e08ac21..1d7ab41 100644 --- a/Lite/Controls/ServerTab.xaml.cs +++ b/Lite/Controls/ServerTab.xaml.cs @@ -5365,7 +5365,9 @@ private async void LiveSnapshot_Click(object sender, RoutedEventArgs e) ConnectTimeout = 15 }; - var query = RemoteCollectorService.BuildQuerySnapshotsQuery(supportsLiveQueryPlan: true, isAzureSqlDatabase: _isAzureSqlDatabase); + // Live query plans require VIEW SERVER PERFORMANCE STATE on Azure SQL DB, + // which DB-scoped logins don't have — skip them there. See #857. + var query = RemoteCollectorService.BuildQuerySnapshotsQuery(supportsLiveQueryPlan: !_isAzureSqlDatabase, isAzureSqlDatabase: _isAzureSqlDatabase); await using var connection = new SqlConnection(builder.ConnectionString); await connection.OpenAsync(); diff --git a/Lite/Services/RemoteCollectorService.QuerySnapshots.cs b/Lite/Services/RemoteCollectorService.QuerySnapshots.cs index 5148af4..c18523c 100644 --- a/Lite/Services/RemoteCollectorService.QuerySnapshots.cs +++ b/Lite/Services/RemoteCollectorService.QuerySnapshots.cs @@ -217,11 +217,18 @@ internal static string BuildQuerySnapshotsQuery(bool supportsLiveQueryPlan, bool /// private async Task CollectQuerySnapshotsAsync(ServerConnection server, CancellationToken cancellationToken) { - // dm_exec_query_statistics_xml requires SQL Server 2016 SP1+ (version 13) + /* + * sys.dm_exec_query_statistics_xml requires SQL Server 2016 SP1+ (version 13) + * on boxed, and VIEW SERVER PERFORMANCE STATE on Azure SQL Database regardless + * of tier. DB-scoped logins (e.g. D365FO) don't have the server-level grant + * and the DMF raises error 300 even when only called for current-DB sessions, + * so we disable live query plans on Azure SQL DB entirely. See #857. + */ var serverStatus = _serverManager.GetConnectionStatus(server.Id); - var supportsLiveQueryPlan = serverStatus.SqlMajorVersion >= 13 || serverStatus.SqlMajorVersion == 0 - || serverStatus.SqlEngineEdition == 5 || serverStatus.SqlEngineEdition == 8; var isAzureSqlDatabase = serverStatus.SqlEngineEdition == 5; + var supportsLiveQueryPlan = !isAzureSqlDatabase + && (serverStatus.SqlMajorVersion >= 13 || serverStatus.SqlMajorVersion == 0 + || serverStatus.SqlEngineEdition == 8); var query = BuildQuerySnapshotsQuery(supportsLiveQueryPlan, isAzureSqlDatabase);