Fixed #4800 need to use ConnectionProfile in order to get the correct… (#4812)

* Fixed #4800 need to use ConnectionProfile in order to get the correct connection

* Go back to create connect in run cell to avoid to fail to run cell or close the connection used by other.
This commit is contained in:
Yurong He
2019-04-03 19:00:56 -07:00
committed by GitHub
parent a34692b6f2
commit 504d5c91bc
3 changed files with 14 additions and 10 deletions

View File

@@ -637,19 +637,19 @@ export class NotebookModel extends Disposable implements INotebookModel {
return spec; return spec;
} }
public async changeContext(server: string, newConnection?: ConnectionProfile, hideErrorMessage?: boolean): Promise<void> { public async changeContext(title: string, newConnection?: ConnectionProfile, hideErrorMessage?: boolean): Promise<void> {
try { try {
if (!newConnection) { if (!newConnection) {
newConnection = this._activeContexts.otherConnections.find((connection) => connection.serverName === server); newConnection = this._activeContexts.otherConnections.find((connection) => connection.title === title);
} }
if ((!newConnection) && (this._activeContexts.defaultConnection.serverName === server)) { if ((!newConnection) && (this._activeContexts.defaultConnection.title === title)) {
newConnection = this._activeContexts.defaultConnection; newConnection = this._activeContexts.defaultConnection;
} }
if (this._activeConnection) {
this._otherConnections.push(this._activeConnection);
}
if (newConnection) { if (newConnection) {
if (this._activeConnection && this._activeConnection.id !== newConnection.id) {
this._otherConnections.push(this._activeConnection);
}
this._activeConnection = newConnection; this._activeConnection = newConnection;
this.refreshConnections(newConnection); this.refreshConnections(newConnection);
this._activeClientSession.updateConnection(newConnection.toIConnectionProfile()).then( this._activeClientSession.updateConnection(newConnection.toIConnectionProfile()).then(

View File

@@ -389,8 +389,8 @@ export class AttachToDropdown extends SelectBox {
else { else {
connections.push(msgAddNewConnection); connections.push(msgAddNewConnection);
} }
this.setOptions(connections);
} }
this.setOptions(connections);
} }
} }

View File

@@ -23,6 +23,7 @@ import { escape } from 'sql/base/common/strings';
import { elapsedTimeLabel } from 'sql/parts/query/common/localizedConstants'; import { elapsedTimeLabel } from 'sql/parts/query/common/localizedConstants';
import * as notebookUtils from 'sql/parts/notebook/notebookUtils'; import * as notebookUtils from 'sql/parts/notebook/notebookUtils';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
export const sqlKernelError: string = localize("sqlKernelError", "SQL kernel error"); export const sqlKernelError: string = localize("sqlKernelError", "SQL kernel error");
export const MAX_ROWS = 5000; export const MAX_ROWS = 5000;
@@ -138,6 +139,7 @@ export class SqlSession implements nb.ISession {
class SqlKernel extends Disposable implements nb.IKernel { class SqlKernel extends Disposable implements nb.IKernel {
private _queryRunner: QueryRunner; private _queryRunner: QueryRunner;
private _currentConnection: IConnectionProfile; private _currentConnection: IConnectionProfile;
private _currentConnectionProfile: ConnectionProfile;
static kernelId: number = 0; static kernelId: number = 0;
private _id: string; private _id: string;
@@ -146,6 +148,7 @@ class SqlKernel extends Disposable implements nb.IKernel {
private _magicToExecutorMap = new Map<string, ExternalScriptMagic>(); private _magicToExecutorMap = new Map<string, ExternalScriptMagic>();
constructor(@IConnectionManagementService private _connectionManagementService: IConnectionManagementService, constructor(@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
@IInstantiationService private _instantiationService: IInstantiationService, @IInstantiationService private _instantiationService: IInstantiationService,
@IErrorMessageService private _errorMessageService: IErrorMessageService, @IErrorMessageService private _errorMessageService: IErrorMessageService,
@IConfigurationService private _configurationService: IConfigurationService @IConfigurationService private _configurationService: IConfigurationService
@@ -206,6 +209,7 @@ class SqlKernel extends Disposable implements nb.IKernel {
public set connection(conn: IConnectionProfile) { public set connection(conn: IConnectionProfile) {
this._currentConnection = conn; this._currentConnection = conn;
this._currentConnectionProfile = new ConnectionProfile(this._capabilitiesService, this._currentConnection);
this._queryRunner = undefined; this._queryRunner = undefined;
} }
@@ -224,10 +228,10 @@ class SqlKernel extends Disposable implements nb.IKernel {
this._future.handleDone(); this._future.handleDone();
} }
this._queryRunner.runQuery(code); this._queryRunner.runQuery(code);
} else if (this._currentConnection) { } else if (this._currentConnection && this._currentConnectionProfile) {
let connectionUri = Utils.generateUri(this._currentConnection, 'notebook'); let connectionUri = Utils.generateUri(this._currentConnectionProfile, 'notebook');
this._queryRunner = this._instantiationService.createInstance(QueryRunner, connectionUri); this._queryRunner = this._instantiationService.createInstance(QueryRunner, connectionUri);
this._connectionManagementService.connect(this._currentConnection, connectionUri).then((result) => { this._connectionManagementService.connect(this._currentConnectionProfile, connectionUri).then((result) => {
this.addQueryEventListeners(this._queryRunner); this.addQueryEventListeners(this._queryRunner);
this._queryRunner.runQuery(code); this._queryRunner.runQuery(code);
}); });