Skip to content

Scope query snapshots to current database on Azure SQL DB (#857)#861

Merged
erikdarlingdata merged 1 commit intodevfrom
fix/857-live-snapshot-azure-scope
Apr 18, 2026
Merged

Scope query snapshots to current database on Azure SQL DB (#857)#861
erikdarlingdata merged 1 commit intodevfrom
fix/857-live-snapshot-azure-scope

Conversation

@erikdarlingdata
Copy link
Copy Markdown
Owner

Summary

Follow-up to #858. @TrudAX reported that the Live Snapshot button still errored on his D365FO Azure SQL Database after the collector fallback shipped. Root cause: sys.dm_exec_requests can surface rows for databases the login can't resolve (typically master-scoped activity), and the subsequent OUTER APPLYs to sys.dm_exec_sql_text / sys.dm_exec_text_query_plan blow up.

On Azure SQL DB, scoping the query snapshots result set to the current database is both correct and sufficient — sys.dm_exec_requests on Azure SQL DB is already per-connection and the user DB is the only DB the login is guaranteed to access.

  • BuildQuerySnapshotsQuery takes a new isAzureSqlDatabase flag and emits AND der.database_id = DB_ID() only when true
  • Collector path pulls SqlEngineEdition from the cached ServerConnectionStatus (already did — just added the flag derivation)
  • Live Snapshot button path gets the flag through a new ServerTab constructor parameter wired from MainWindow
  • Boxed SQL Server, Managed Instance, and elastic pool behavior is unchanged

Verified on a fresh Azure SQL DB (GP_S_Gen5) — DB_ID() (no args) returns the current DB, the scoped query runs cleanly, and activity from the current DB shows up in Live Snapshot.

Test plan

  • Build: dotnet build Lite/PerformanceMonitorLite.csproj -c Debug — 0 errors
  • Azure SQL DB smoke test: Live Snapshot button returns results for testdb-scoped activity only, no master rows
  • Boxed SQL Server: unchanged behavior, no new predicate emitted
  • D365FO environment confirmation (deferred to @TrudAX when merged to dev)

🤖 Generated with Claude Code

On Azure SQL Database, logins without access to master can't resolve
cross-database rows returned by sys.dm_exec_requests, which caused the
Live Snapshot button and the query snapshots collector to error in
D365FO-style environments (reported by @TrudAX in #857 after PR #858).

BuildQuerySnapshotsQuery now takes an isAzureSqlDatabase flag and emits
AND der.database_id = DB_ID() only when true. Boxed SQL Server, MI, and
elastic pool behavior is unchanged. The Live Snapshot button path gets
the flag through a new ServerTab constructor parameter wired from the
cached ServerConnectionStatus.SqlEngineEdition.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit e41c960 into dev Apr 18, 2026
3 checks passed
@erikdarlingdata erikdarlingdata deleted the fix/857-live-snapshot-azure-scope branch April 19, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant