mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
ML - Verifying ODBC Driver (#11587)
* Verifying ODBC is installed before opening package manager dialog
This commit is contained in:
@@ -120,6 +120,8 @@ export class PackageManager {
|
||||
await utils.executeTasks(this._apiWrapper, constants.installPackageMngDependenciesMsgTaskName, [
|
||||
this.installRequiredPythonPackages(this._config.requiredSqlPythonPackages),
|
||||
this.installRequiredRPackages()], true);
|
||||
|
||||
await this.verifyOdbcInstalled();
|
||||
}
|
||||
|
||||
private async installRequiredRPackages(): Promise<void> {
|
||||
@@ -186,6 +188,45 @@ export class PackageManager {
|
||||
}
|
||||
}
|
||||
|
||||
private async verifyOdbcInstalled(): Promise<void> {
|
||||
let connection = await this.getCurrentConnection();
|
||||
if (connection) {
|
||||
let credentials = await this._apiWrapper.getCredentials(connection.connectionId);
|
||||
const separator = '=';
|
||||
let connectionParts: string[] = [];
|
||||
if (connection) {
|
||||
connectionParts.push(utils.getKeyValueString('DRIVER', `{${constants.supportedODBCDriver}}`, separator));
|
||||
|
||||
if (connection.userName) {
|
||||
connectionParts.push(utils.getKeyValueString('UID', connection.userName, separator));
|
||||
connectionParts.push(utils.getKeyValueString('PWD', credentials[azdata.ConnectionOptionSpecialType.password], separator));
|
||||
} else {
|
||||
connectionParts.push(utils.getKeyValueString('Trusted_Connection', 'yes', separator));
|
||||
|
||||
}
|
||||
|
||||
connectionParts.push(utils.getKeyValueString('SERVER', connection.serverName, separator));
|
||||
}
|
||||
|
||||
let scripts: string[] = [
|
||||
'import pyodbc',
|
||||
`connection = pyodbc.connect('${connectionParts.join(';')}')`,
|
||||
'cursor = connection.cursor()',
|
||||
'cursor.execute("SELECT @@version;")'
|
||||
];
|
||||
let pythonExecutable = await this._config.getPythonExecutable(true);
|
||||
try {
|
||||
await this._processService.execScripts(pythonExecutable, scripts, [], this._outputChannel);
|
||||
} catch (err) {
|
||||
const result = await this._apiWrapper.showErrorMessage(constants.verifyOdbcDriverError, constants.learnMoreTitle);
|
||||
if (result === constants.learnMoreTitle) {
|
||||
await this._apiWrapper.openExternal(vscode.Uri.parse(constants.odbcDriverDocuments));
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async getInstalledPipPackages(): Promise<nbExtensionApis.IPackageDetails[]> {
|
||||
try {
|
||||
let pythonExecutable = await this.getPythonExecutable();
|
||||
|
||||
Reference in New Issue
Block a user