diff --git a/src/sql/parts/notebook/models/modelInterfaces.ts b/src/sql/parts/notebook/models/modelInterfaces.ts index 105bbad69e..b09b794210 100644 --- a/src/sql/parts/notebook/models/modelInterfaces.ts +++ b/src/sql/parts/notebook/models/modelInterfaces.ts @@ -341,7 +341,7 @@ export interface INotebookModel { /** * Change the current context (if applicable) */ - changeContext(host: string, connection?: IConnectionProfile): Promise; + changeContext(host: string, connection?: IConnectionProfile, hideErrorMessage?: boolean): Promise; /** * Find a cell's index given its model diff --git a/src/sql/parts/notebook/models/notebookModel.ts b/src/sql/parts/notebook/models/notebookModel.ts index d4a5df5bed..bea819609e 100644 --- a/src/sql/parts/notebook/models/notebookModel.ts +++ b/src/sql/parts/notebook/models/notebookModel.ts @@ -449,7 +449,7 @@ export class NotebookModel extends Disposable implements INotebookModel { return Promise.resolve(); } - public async changeContext(server: string, newConnection?: IConnectionProfile): Promise { + public async changeContext(server: string, newConnection?: IConnectionProfile, hideErrorMessage?: boolean): Promise { try { if (!newConnection) { newConnection = this._activeContexts.otherConnections.find((connection) => connection.serverName === server); @@ -467,7 +467,9 @@ export class NotebookModel extends Disposable implements INotebookModel { }, error => { if (error) { - this.notifyError(notebookUtils.getErrorMessage(error)); + if (!hideErrorMessage) { + this.notifyError(notebookUtils.getErrorMessage(error)); + } //Selected a wrong connection, Attach to should be defaulted with 'Select connection' this._onValidConnectionSelected.fire(false); } diff --git a/src/sql/parts/notebook/notebookActions.ts b/src/sql/parts/notebook/notebookActions.ts index 0747ff14b4..38541e72b7 100644 --- a/src/sql/parts/notebook/notebookActions.ts +++ b/src/sql/parts/notebook/notebookActions.ts @@ -392,11 +392,11 @@ export class AttachToDropdown extends SelectBox { return otherConnections; } - public doChangeContext(connection?: ConnectionProfile): void { + public doChangeContext(connection?: ConnectionProfile, hideErrorMessage?: boolean): void { if (this.value === msgAddNewConnection) { this.openConnectionDialog(); } else { - this.model.changeContext(this.value, connection).then(ok => undefined, err => this._notificationService.error(getErrorMessage(err))); + this.model.changeContext(this.value, connection, hideErrorMessage).then(ok => undefined, err => this._notificationService.error(getErrorMessage(err))); } } @@ -412,6 +412,7 @@ export class AttachToDropdown extends SelectBox { let attachToConnections = this.values; if (!connection) { this.loadAttachToDropdown(this.model, this.getKernelDisplayName()); + this.doChangeContext(undefined, true); return; } let connectionProfile = new ConnectionProfile(this._capabilitiesService, connection); diff --git a/src/sqltest/parts/notebook/common.ts b/src/sqltest/parts/notebook/common.ts index 7e1e65b42e..f10e000300 100644 --- a/src/sqltest/parts/notebook/common.ts +++ b/src/sqltest/parts/notebook/common.ts @@ -69,7 +69,7 @@ export class NotebookModelStub implements INotebookModel { changeKernel(displayName: string): void { throw new Error('Method not implemented.'); } - changeContext(host: string, connection?: IConnectionProfile): Promise { + changeContext(host: string, connection?: IConnectionProfile, hideErrorMessage?: boolean): Promise { throw new Error('Method not implemented.'); } findCellIndex(cellModel: ICellModel): number {