Description
When a user has access to the same Azure subscription through multiple accounts (e.g., personal and work accounts), the subscription filter dialog exhibited several issues, reportedhere:
Duplicate Selection Bug: Selecting one instance of a subscription would automatically select all instances across different accounts
Missing Subscriptions: Not all subscriptions were visible in the filter dropdown, even when no filtering was applied
Missing Tenants: Not all tenants for an account were displayed in the connection dialog
Error on Load: "Error loading Azure subscriptions" appeared when the same subscription existed under multiple accounts
Root Cause Analysis
Issue 1: Tenant Discovery
Problem: auth.getTenants(account) with an account parameter wasn't reliably returning all tenants for an account, particularly for newly added tenants where the user hadn't explicitly signed in through VS Code.
Fix: Changed from auth.getTenants(account) to auth.getTenants() (without account parameter) to fetch ALL tenants across all accounts, then filter by account ID client-side. This ensures all tenants are discovered regardless of authentication state.
Issue 2: Token Refresh
Problem: VS Code's Azure authentication system only returns subscriptions from tenants where it has active authentication tokens. Newly added tenants/subscriptions weren't discovered until explicit authentication.
Fix: Added refreshAzureTokensForAllAccounts() method that proactively signs into all tenants for all accounts when the connection dialog opens, ensuring all subscriptions are discoverable.
Issue 3: Subscription Storage Collisions
Problem: The subscription filter used a composite key format tenantId/subscriptionId, which is not unique when the same subscription is accessible from multiple accounts. This caused:
- Subscriptions stored in a Map<subscriptionId, AzureSubscription> to overwrite each other
- Filter configuration to store duplicate entries
- UI to show both instances as selected when only one was chosen
Fix: Changed composite key format from tenantId/subscriptionId to account/tenantId/subscriptionId to ensure uniqueness. Updated all related code:
- Subscription Map storage
- Filter configuration format
- getTenantFilters() and getSubscriptionFilters() parsing logic
- Tenant ID population in subscription info
Changes Made
Core Logic Changes
- azureHelpers.ts
- Modified getTenantsForAccount() to fetch all tenants then filter by account
- Updated composite key generation: ${sub.account.label}/${sub.tenantId}/${sub.subscriptionId}
- Updated promptForAzureSubscriptionFilter() to use new composite key format
- Enhanced getSubscriptionQuickPickItems() to include account label in description for disambiguation
- connectionDialogWebviewController.ts
- Added refreshAzureTokensForAllAccounts() method to proactively ensure tokens exist for all tenants
- Modified loadAzureSubscriptions() to call token refresh before fetching subscriptions
- Updated subscription Map key from subscriptionId to ${tenantId}/${subscriptionId}
- Updated loadAzureServersForSubscription() to accept both tenantId and subscriptionId parameters
- Modified reducer to extract tenantId from state when loading servers
- Added tenant count to telemetry for tracking scenario where users have multiple tenants
- MssqlVSCodeAzureSubscriptionProvider.ts
- Updated getTenantFilters() to parse index 1 from 3-part composite key
- Updated getSubscriptionFilters() to parse index 2 from 3-part composite key
- connectionDialog.ts
- Added tenantId: string field to AzureSubscriptionInfo interface
- azureBrowsePage.tsx
- Changed server selection mode from SelectFirstIfAny to AlwaysSelectNone (prevents auto-selection)
- Added proper cleanup of database selection when server selection becomes invalid
Testing
New Test File: MssqlVSCodeAzureSubscriptionProvider.test.ts:
- getTenantFilters extracts tenant IDs from composite keys
- getSubscriptionFilters extracts subscription IDs from composite keys
- getTenantFilters handles empty configuration
- getSubscriptionFilters handles empty configuration
- filters correctly handle duplicate subscriptions from different accounts
- filters correctly parse complex email addresses
Enhanced Test File: azureHelpers.test.ts:
- creates pick items with account-based composite keys
- respects previous selection with account-based composite keys
- handles complex email addresses in composite keys
UI Updates
Before:
- Subscription filter showed duplicate selections for shared subscriptions:


- Not all subscriptions visible even without filters
- Auto-selected servers inappropriately
- Error messages when loading subscriptions
After:
- Each subscription+account combination is independently selectable

- All subscriptions from all tenants are discoverable on dialog open

- Subscription filter accurately reflects user selection- No auto-selection of servers/databases unless explicitly chosen- Clear visual distinction in UI showing account email in subscription description
Breaking Changes
Configuration Format Change: Existing subscription filters stored as tenantId/subscriptionId will need to be reset. Users with active filters will see all subscriptions unfiltered on first use after update and will need to re-select their desired subscriptions. This is intentional to avoid migration complexity and ensure clean state.
The change maintains backward compatibility with the VS Code Azure SDK and doesn't affect users who:
- Only have one Azure account
- Don't have duplicate subscriptions across accounts
- Haven't set up subscription filters
- Related: This fix also resolves the server auto-selection issue mentioned in the original report where servers were being selected even when filters weren't specified.
Code Changes Checklist
Uh oh!
There was an error while loading.Please reload this page.
Description
When a user has access to the same Azure subscription through multiple accounts (e.g., personal and work accounts), the subscription filter dialog exhibited several issues, reportedhere:
Duplicate Selection Bug: Selecting one instance of a subscription would automatically select all instances across different accounts
Missing Subscriptions: Not all subscriptions were visible in the filter dropdown, even when no filtering was applied
Missing Tenants: Not all tenants for an account were displayed in the connection dialog
Error on Load: "Error loading Azure subscriptions" appeared when the same subscription existed under multiple accounts
Root Cause Analysis
Issue 1: Tenant Discovery
Problem: auth.getTenants(account) with an account parameter wasn't reliably returning all tenants for an account, particularly for newly added tenants where the user hadn't explicitly signed in through VS Code.
Fix: Changed from auth.getTenants(account) to auth.getTenants() (without account parameter) to fetch ALL tenants across all accounts, then filter by account ID client-side. This ensures all tenants are discovered regardless of authentication state.
Issue 2: Token Refresh
Problem: VS Code's Azure authentication system only returns subscriptions from tenants where it has active authentication tokens. Newly added tenants/subscriptions weren't discovered until explicit authentication.
Fix: Added refreshAzureTokensForAllAccounts() method that proactively signs into all tenants for all accounts when the connection dialog opens, ensuring all subscriptions are discoverable.
Issue 3: Subscription Storage Collisions
Problem: The subscription filter used a composite key format tenantId/subscriptionId, which is not unique when the same subscription is accessible from multiple accounts. This caused:
Fix: Changed composite key format from tenantId/subscriptionId to account/tenantId/subscriptionId to ensure uniqueness. Updated all related code:
Changes Made
Core Logic Changes
Testing
New Test File: MssqlVSCodeAzureSubscriptionProvider.test.ts:
Enhanced Test File: azureHelpers.test.ts:
UI Updates
Before:
After:
Breaking Changes
Configuration Format Change: Existing subscription filters stored as tenantId/subscriptionId will need to be reset. Users with active filters will see all subscriptions unfiltered on first use after update and will need to re-select their desired subscriptions. This is intentional to avoid migration complexity and ensure clean state.
The change maintains backward compatibility with the VS Code Azure SDK and doesn't affect users who:
Code Changes Checklist
npm run test)Reviewers:Please read our reviewer guidelines