mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Fix Notebook Connection Issues (#6831)
This commit is contained in:
@@ -24,6 +24,7 @@ import { isUndefinedOrNull } from 'vs/base/common/types';
|
|||||||
import { ILanguageMagic } from 'sql/workbench/services/notebook/common/notebookService';
|
import { ILanguageMagic } from 'sql/workbench/services/notebook/common/notebookService';
|
||||||
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
|
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
|
||||||
import { URI } from 'vs/base/common/uri';
|
import { URI } from 'vs/base/common/uri';
|
||||||
|
import { getUriPrefix, uriPrefixes } from 'sql/platform/connection/common/utils';
|
||||||
|
|
||||||
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;
|
||||||
@@ -162,6 +163,7 @@ class SqlKernel extends Disposable implements nb.IKernel {
|
|||||||
private _future: SQLFuture;
|
private _future: SQLFuture;
|
||||||
private _executionCount: number = 0;
|
private _executionCount: number = 0;
|
||||||
private _magicToExecutorMap = new Map<string, ExternalScriptMagic>();
|
private _magicToExecutorMap = new Map<string, ExternalScriptMagic>();
|
||||||
|
private _connectionPath: string;
|
||||||
|
|
||||||
constructor(private _path: string,
|
constructor(private _path: string,
|
||||||
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
||||||
@@ -174,6 +176,7 @@ class SqlKernel extends Disposable implements nb.IKernel {
|
|||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.initMagics();
|
this.initMagics();
|
||||||
|
this.setConnectionPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
private initMagics(): void {
|
private initMagics(): void {
|
||||||
@@ -183,6 +186,29 @@ class SqlKernel extends Disposable implements nb.IKernel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setConnectionPath(): void {
|
||||||
|
if (this._path) {
|
||||||
|
let prefix = getUriPrefix(this._path);
|
||||||
|
if (!prefix || prefix === uriPrefixes.connection) {
|
||||||
|
this._connectionPath = uriPrefixes.notebook.concat(this._path);
|
||||||
|
} else if (prefix !== uriPrefixes.notebook) {
|
||||||
|
try {
|
||||||
|
let uri = URI.parse(this._path);
|
||||||
|
if (uri && uri.scheme) {
|
||||||
|
this._connectionPath = uri.toString().replace(uri.scheme, uriPrefixes.notebook);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Ignore exceptions from URI parsing
|
||||||
|
} finally {
|
||||||
|
// If _connectionPath hasn't been set yet, set _connectionPath to _path as a last resort
|
||||||
|
if (!this._connectionPath) {
|
||||||
|
this._connectionPath = this._path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public get id(): string {
|
public get id(): string {
|
||||||
if (this._id === undefined) {
|
if (this._id === undefined) {
|
||||||
this._id = (SqlKernel.kernelId++).toString();
|
this._id = (SqlKernel.kernelId++).toString();
|
||||||
@@ -252,8 +278,8 @@ class SqlKernel extends Disposable implements nb.IKernel {
|
|||||||
}
|
}
|
||||||
this._queryRunner.runQuery(code);
|
this._queryRunner.runQuery(code);
|
||||||
} else if (this._currentConnection && this._currentConnectionProfile) {
|
} else if (this._currentConnection && this._currentConnectionProfile) {
|
||||||
this._queryRunner = this._instantiationService.createInstance(QueryRunner, this._path);
|
this._queryRunner = this._instantiationService.createInstance(QueryRunner, this._connectionPath);
|
||||||
this._connectionManagementService.connect(this._currentConnectionProfile, this._path).then((result) => {
|
this._connectionManagementService.connect(this._currentConnectionProfile, this._connectionPath).then((result) => {
|
||||||
this.addQueryEventListeners(this._queryRunner);
|
this.addQueryEventListeners(this._queryRunner);
|
||||||
this._queryRunner.runQuery(code);
|
this._queryRunner.runQuery(code);
|
||||||
});
|
});
|
||||||
@@ -332,10 +358,10 @@ class SqlKernel extends Disposable implements nb.IKernel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async disconnect(): Promise<void> {
|
public async disconnect(): Promise<void> {
|
||||||
if (this._path) {
|
if (this._connectionPath) {
|
||||||
if (this._connectionManagementService.isConnected(this._path)) {
|
if (this._connectionManagementService.isConnected(this._connectionPath)) {
|
||||||
try {
|
try {
|
||||||
await this._connectionManagementService.disconnect(this._path);
|
await this._connectionManagementService.disconnect(this._connectionPath);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logService.error(err);
|
this.logService.error(err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user