diff --git a/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs b/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs index 07cd369..8a90a2e 100644 --- a/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs +++ b/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs @@ -495,12 +495,16 @@ private async void ExecuteEstimated_Click(object? sender, RoutedEventArgs e) private async Task CaptureAndShowPlan(bool estimated, string? queryTextOverride = null) { - if (_connectionString == null || _selectedDatabase == null) + if (_serverConnection == null || _selectedDatabase == null) { SetStatus("Connect to a server first", autoClear: false); return; } + // Always rebuild connection string from current database selection + // to guarantee the picker state is reflected at execution time + _connectionString = _serverConnection.GetConnectionString(_credentialService, _selectedDatabase); + var queryText = queryTextOverride?.Trim() ?? GetSelectedTextOrNull()?.Trim() ?? QueryEditor.Text?.Trim();