mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Update schema compare extension to support SQL Login (#8567)
* Update schema compare extension to support SQL Login * Update schema compare extension to support SQL Login * Fixed the scenario where scmp file doesn't open as expected- cleaning up previous connect information and setting appropriate button states if either source or target info is missing. Also updated function getEndpointName to return empty string if serverName and databaseName aren't present, instead of partial information. * Addressed comments. Fixed var names and moved repeatitive code in a helper function.
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
import * as nls from 'vscode-nls';
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as mssql from '../../mssql';
|
||||
import * as os from 'os';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export interface IPackageInfo {
|
||||
name: string;
|
||||
@@ -50,7 +52,15 @@ export function getEndpointName(endpoint: mssql.SchemaCompareEndpointInfo): stri
|
||||
if (!endpoint.serverName && endpoint.connectionDetails) {
|
||||
endpoint.serverName = endpoint.connectionDetails['serverName'];
|
||||
}
|
||||
return `${endpoint.serverName}.${endpoint.databaseName}`;
|
||||
if (!endpoint.databaseName && endpoint.connectionDetails) {
|
||||
endpoint.databaseName = endpoint.connectionDetails['databaseName'];
|
||||
}
|
||||
if (endpoint.serverName && endpoint.databaseName) {
|
||||
return `${endpoint.serverName}.${endpoint.databaseName}`;
|
||||
} else {
|
||||
return ' ';
|
||||
}
|
||||
|
||||
} else {
|
||||
return endpoint.packageFilePath;
|
||||
}
|
||||
@@ -74,17 +84,44 @@ function connectionInfoToConnectionProfile(details: azdata.ConnectionInfo): azda
|
||||
};
|
||||
}
|
||||
|
||||
export async function verifyConnectionAndGetOwnerUri(endpoint: mssql.SchemaCompareEndpointInfo): Promise<string> {
|
||||
export async function verifyConnectionAndGetOwnerUri(endpoint: mssql.SchemaCompareEndpointInfo, caller: string): Promise<string> {
|
||||
let ownerUri = undefined;
|
||||
if (endpoint.endpointType === mssql.SchemaCompareEndpointType.Database && endpoint.connectionDetails) {
|
||||
let connection = await azdata.connection.connect(connectionInfoToConnectionProfile(endpoint.connectionDetails), false, false);
|
||||
let connectionProfile = await connectionInfoToConnectionProfile(endpoint.connectionDetails);
|
||||
let connection = await azdata.connection.connect(connectionProfile, false, false);
|
||||
if (connection) {
|
||||
ownerUri = await azdata.connection.getUriForConnection(connection.connectionId);
|
||||
if (!ownerUri) {
|
||||
let connectionList = await azdata.connection.getConnections(true);
|
||||
let userConnection;
|
||||
userConnection = connectionList.find(connection =>
|
||||
(endpoint.connectionDetails['authenticationType'] === 'SqlLogin'
|
||||
&& endpoint.connectionDetails['serverName'] === connection.options.server
|
||||
&& endpoint.connectionDetails['userName'] === connection.options.user
|
||||
&& (endpoint.connectionDetails['databaseName'].toLowerCase() === connection.options.database.toLowerCase()
|
||||
|| connection.options.database.toLowerCase() === 'master')));
|
||||
|
||||
// show error message if the can't connect to the database
|
||||
if (connection.errorMessage) {
|
||||
vscode.window.showErrorMessage(connection.errorMessage);
|
||||
if (userConnection === undefined) {
|
||||
const getConnectionString = localize('schemaCompare.GetConnectionString', "Do you want to connect to {0}?", caller);
|
||||
// need only yes button - since the modal dialog has a default cancel
|
||||
const yesString = localize('schemaCompare.ApplyYes', "Yes");
|
||||
|
||||
let result = await vscode.window.showWarningMessage(getConnectionString, { modal: true }, yesString);
|
||||
if (result === yesString) {
|
||||
userConnection = await azdata.connection.openConnectionDialog(undefined, connectionProfile);
|
||||
}
|
||||
}
|
||||
|
||||
if (userConnection !== undefined) {
|
||||
ownerUri = await azdata.connection.getUriForConnection(userConnection.connectionId);
|
||||
}
|
||||
}
|
||||
if (!ownerUri && connection.errorMessage) {
|
||||
vscode.window.showErrorMessage(connection.errorMessage);
|
||||
}
|
||||
}
|
||||
return await azdata.connection.getUriForConnection(connection.connectionId);
|
||||
}
|
||||
return undefined;
|
||||
return ownerUri;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user