From 2b111c6bfd9b6703f4829200c6f9131ab86fed37 Mon Sep 17 00:00:00 2001 From: Kim Santiago <31145923+kisantia@users.noreply.github.com> Date: Tue, 31 Mar 2020 16:32:30 -0700 Subject: [PATCH] fix schema compare database dropdown when the user doesn't have access to master (#9813) --- .../src/dialogs/schemaCompareDialog.ts | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts b/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts index da4034a0c2..dd04183f04 100644 --- a/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts +++ b/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts @@ -103,7 +103,7 @@ export class SchemaCompareDialog { endpointType: mssql.SchemaCompareEndpointType.Database, serverDisplayName: (this.sourceServerDropdown.value as ConnectionDropdownValue).displayName, serverName: (this.sourceServerDropdown.value as ConnectionDropdownValue).name, - databaseName: (this.sourceDatabaseDropdown.value).name, + databaseName: this.sourceDatabaseDropdown.value.toString(), ownerUri: ownerUri, packageFilePath: '', connectionDetails: undefined @@ -127,7 +127,7 @@ export class SchemaCompareDialog { endpointType: mssql.SchemaCompareEndpointType.Database, serverDisplayName: (this.targetServerDropdown.value as ConnectionDropdownValue).displayName, serverName: (this.targetServerDropdown.value as ConnectionDropdownValue).name, - databaseName: (this.targetDatabaseDropdown.value).name, + databaseName: this.targetDatabaseDropdown.value.toString(), ownerUri: ownerUri, packageFilePath: '', connectionDetails: undefined @@ -204,7 +204,7 @@ export class SchemaCompareDialog { this.sourceDatabaseComponent = await this.createSourceDatabaseDropdown(view); if ((this.sourceServerDropdown.value as ConnectionDropdownValue)) { - await this.populateDatabaseDropdown((this.sourceServerDropdown.value as ConnectionDropdownValue).connection.connectionId, false); + await this.populateDatabaseDropdown((this.sourceServerDropdown.value as ConnectionDropdownValue).connection, false); } this.targetServerComponent = await this.createTargetServerDropdown(view); @@ -212,7 +212,7 @@ export class SchemaCompareDialog { this.targetDatabaseComponent = await this.createTargetDatabaseDropdown(view); if ((this.targetServerDropdown.value as ConnectionDropdownValue)) { - await this.populateDatabaseDropdown((this.targetServerDropdown.value as ConnectionDropdownValue).connection.connectionId, true); + await this.populateDatabaseDropdown((this.targetServerDropdown.value as ConnectionDropdownValue).connection, true); } this.sourceDacpacComponent = await this.createFileBrowser(view, false, this.schemaCompareResult.sourceEndpointInfo); @@ -477,7 +477,7 @@ export class SchemaCompareDialog { }); } else { - await this.populateDatabaseDropdown((this.sourceServerDropdown.value as ConnectionDropdownValue).connection.connectionId, false); + await this.populateDatabaseDropdown((this.sourceServerDropdown.value as ConnectionDropdownValue).connection, false); } }); @@ -503,7 +503,7 @@ export class SchemaCompareDialog { }); } else { - await this.populateDatabaseDropdown((this.targetServerDropdown.value as ConnectionDropdownValue).connection.connectionId, true); + await this.populateDatabaseDropdown((this.targetServerDropdown.value as ConnectionDropdownValue).connection, true); } }); @@ -627,11 +627,18 @@ export class SchemaCompareDialog { return listValue.displayName === value || listValue === value; } - protected async populateDatabaseDropdown(connectionId: string, isTarget: boolean): Promise { + protected async populateDatabaseDropdown(connectionProfile: azdata.connection.ConnectionProfile, isTarget: boolean): Promise { let currentDropdown = isTarget ? this.targetDatabaseDropdown : this.sourceDatabaseDropdown; currentDropdown.updateProperties({ values: [], value: null }); - let values = await this.getDatabaseValues(connectionId, isTarget); + let values = []; + try { + values = await this.getDatabaseValues(connectionProfile.connectionId, isTarget); + } catch (e) { + // if the user doesn't have access to master, just set the database of the connection profile + values = [connectionProfile.databaseName]; + console.warn(e); + } if (values && values.length > 0) { currentDropdown.updateProperties({ values: values, @@ -640,7 +647,7 @@ export class SchemaCompareDialog { } } - protected async getDatabaseValues(connectionId: string, isTarget: boolean): Promise<{ displayName, name }[]> { + protected async getDatabaseValues(connectionId: string, isTarget: boolean): Promise { let endpointInfo = isTarget ? this.schemaCompareResult.targetEndpointInfo : this.schemaCompareResult.sourceEndpointInfo; let idx = -1; @@ -654,10 +661,7 @@ export class SchemaCompareDialog { idx = count; } - return { - displayName: db, - name: db - }; + return db; }); if (idx >= 0) {