Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix export from a MFA-enabled connexion not specifying the database name #11

Merged
merged 1 commit into from
Oct 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export function activate(context: vscode.ExtensionContext) {
return;
}

// Ensure that we run this query in the proper context by prepending a "use {database};"
sql = `Use [${oeContext.connectionProfile.databaseName}]; ` + sql;

let args: ScriptingArgs = {
context: oeContext,
tableName: tableName,
Expand All @@ -49,17 +46,27 @@ export function activate(context: vscode.ExtensionContext) {
async function scriptData(backgroundOperation: azdata.BackgroundOperation, args: ScriptingArgs) {
let connectionResult: azdata.ConnectionResult = await azdata.connection.connect(args.context.connectionProfile, false, false);
if (!connectionResult.connected) {
backgroundOperation.updateStatus(azdata.TaskStatus.Failed, "Could not connect to database");
backgroundOperation.updateStatus(azdata.TaskStatus.Failed, "Could not connect to database server");
vscode.window.showErrorMessage(connectionResult.errorMessage);
return;
}

let connectionUri: string = await azdata.connection.getUriForConnection(connectionResult.connectionId);
let providerId: string = args.context.connectionProfile.providerName;
let databaseName = args.context.connectionProfile.databaseName;

let connectionProvider = azdata.dataprotocol.getProvider<azdata.ConnectionProvider>(providerId, azdata.DataProviderType.ConnectionProvider);
let queryProvider = azdata.dataprotocol.getProvider<azdata.QueryProvider>(providerId, azdata.DataProviderType.QueryProvider);

backgroundOperation.updateStatus(azdata.TaskStatus.InProgress, "Getting records...");

var changeDatabaseResults = await connectionProvider.changeDatabase(connectionUri, databaseName);
if (!changeDatabaseResults) {
backgroundOperation.updateStatus(azdata.TaskStatus.Failed, `Could not switch to [${databaseName}] database`);
vscode.window.showErrorMessage(connectionResult.errorMessage);
return;
}

queryProvider.runQueryAndReturn(connectionUri, args.sqlString).then(
function (results) {
if (!results || results.rowCount === 0) {
Expand All @@ -79,7 +86,7 @@ async function scriptData(backgroundOperation: azdata.BackgroundOperation, args:
});
},
function (error) {
let message = (error instanceof Error) ? error.message : "There was an error retrieving data!";
let message = (error instanceof Error) ? error.message : "There was an unknown error retrieving data";
backgroundOperation.updateStatus(azdata.TaskStatus.Failed, message);
vscode.window.showErrorMessage(message);
});
Expand Down