Preserve name and group when using Connection String (#22341)

This commit is contained in:
Vsevolod Kukol
2023-03-22 15:55:18 +01:00
committed by GitHub
parent 21bb7eb482
commit e3135aca4c

View File

@@ -20,6 +20,7 @@ import { IAccountManagementService } from 'sql/platform/accounts/common/interfac
import * as azdata from 'azdata';
import * as utils from 'vs/base/common/errors';
import * as lifecycle from 'vs/base/common/lifecycle';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { localize } from 'vs/nls';
@@ -1194,12 +1195,17 @@ export class ConnectionWidget extends lifecycle.Disposable {
let validInputs = this.validateInputs();
if (validInputs) {
if (this.useConnectionString) {
const connInfo = await this._connectionManagementService.buildConnectionInfo(this.connectionString, this._providerName);
if (connInfo) {
try {
const connInfo = await this._connectionManagementService.buildConnectionInfo(this.connectionString, this._providerName);
if (!connInfo) {
throw Error(localize('connectionWidget.ConnectionStringUndefined', 'No connection info returned.'));
}
model.options = connInfo.options;
model.savePassword = true;
} else {
this._errorMessageService.showDialog(Severity.Error, localize('connectionWidget.Error', "Error"), localize('connectionWidget.ConnectionStringError', "Failed to parse the connection string."));
} catch (err) {
this._logService.error(`${this._providerName} Failed to parse the connection string : ${err}`)
this._errorMessageService.showDialog(Severity.Error, localize('connectionWidget.Error', "Error"),
localize('connectionWidget.ConnectionStringError', "Failed to parse the connection string. {0}", utils.getErrorMessage(err)), err.stack);
return false;
}
} else {
@@ -1209,26 +1215,26 @@ export class ConnectionWidget extends lifecycle.Disposable {
model.authenticationType = this.authenticationType;
model.azureAccount = this.authToken;
model.savePassword = this._rememberPasswordCheckBox.checked;
model.connectionName = this.connectionName;
model.databaseName = this.databaseName;
if (this._customOptionWidgets) {
this._customOptionWidgets.forEach((widget, i) => {
model.options[this._customOptions[i].name] = widget.value;
});
}
if (this._serverGroupSelectBox) {
if (this._serverGroupSelectBox.value === this.DefaultServerGroup.name) {
model.groupFullName = '';
model.saveProfile = true;
model.groupId = this.findGroupId(model.groupFullName);
} else if (this._serverGroupSelectBox.value === this.NoneServerGroup.name) {
model.groupFullName = '';
model.saveProfile = false;
} else if (this._serverGroupSelectBox.value !== this._addNewServerGroup.name) {
model.groupFullName = this._serverGroupSelectBox.value;
model.saveProfile = true;
model.groupId = this.findGroupId(model.groupFullName);
}
}
model.connectionName = this.connectionName;
if (this._serverGroupSelectBox) {
if (this._serverGroupSelectBox.value === this.DefaultServerGroup.name) {
model.groupFullName = '';
model.saveProfile = true;
model.groupId = this.findGroupId(model.groupFullName);
} else if (this._serverGroupSelectBox.value === this.NoneServerGroup.name) {
model.groupFullName = '';
model.saveProfile = false;
} else if (this._serverGroupSelectBox.value !== this._addNewServerGroup.name) {
model.groupFullName = this._serverGroupSelectBox.value;
model.saveProfile = true;
model.groupId = this.findGroupId(model.groupFullName);
}
}
}