diff --git a/extensions/sql-database-projects/src/models/deploy/deployProfile.ts b/extensions/sql-database-projects/src/models/deploy/deployProfile.ts index f9bc7ea1f7..6e239275dd 100644 --- a/extensions/sql-database-projects/src/models/deploy/deployProfile.ts +++ b/extensions/sql-database-projects/src/models/deploy/deployProfile.ts @@ -27,5 +27,6 @@ export interface ILocalDbSetting { password: string, dbName: string, dockerBaseImage: string, - connectionRetryTimeout?: number + connectionRetryTimeout?: number, + profileName?: string } diff --git a/extensions/sql-database-projects/src/models/deploy/deployService.ts b/extensions/sql-database-projects/src/models/deploy/deployService.ts index 2aedc77eb7..4119c962d7 100644 --- a/extensions/sql-database-projects/src/models/deploy/deployService.ts +++ b/extensions/sql-database-projects/src/models/deploy/deployService.ts @@ -26,7 +26,7 @@ export class DeployService { } private DefaultSqlRetryTimeoutInSec: number = 10; - private DefaultSqlNumberOfRetries: number = 10; + private DefaultSqlNumberOfRetries: number = 3; private createConnectionStringTemplate(runtime: string | undefined): string { switch (runtime?.toLocaleLowerCase()) { @@ -137,6 +137,13 @@ export class DeployService { const dockerFilePath = path.join(mssqlFolderPath, constants.dockerFileName); const startFilePath = path.join(commandsFolderPath, constants.startCommandName); + + // If profile name is not set use the docker name to have a unique name + if (!profile.localDbSetting.profileName) { + profile.localDbSetting.profileName = imageSpec.containerName; + } + + this.logToOutput(constants.cleaningDockerImagesMessage); // Clean up existing docker image const containerIds = await this.getCurrentDockerContainer(imageSpec.label); if (containerIds.length > 0) { @@ -218,7 +225,7 @@ export class DeployService { } // Connects to a database - private async connectToDatabase(profile: ILocalDbSetting, savePassword: boolean, database: string): Promise { + private async connectToDatabase(profile: ILocalDbSetting, saveConnectionAndPassword: boolean, database: string): Promise { const getAzdataApi = await utils.getAzdataApi(); const vscodeMssqlApi = getAzdataApi ? undefined : await utils.getVscodeMssqlApi(); if (getAzdataApi) { @@ -226,12 +233,12 @@ export class DeployService { password: profile.password, serverName: `${profile.serverName},${profile.port}`, database: database, - savePassword: savePassword, + savePassword: saveConnectionAndPassword, userName: profile.userName, providerName: 'MSSQL', saveProfile: false, id: '', - connectionName: `${constants.connectionNamePrefix} ${database}`, + connectionName: `${profile.profileName}`, options: [], authenticationType: 'SqlLogin' }; @@ -242,7 +249,7 @@ export class DeployService { server: `${profile.serverName}`, port: profile.port, database: database, - savePassword: savePassword, + savePassword: saveConnectionAndPassword, user: profile.userName, authenticationType: 'SqlLogin', encrypt: false, @@ -269,9 +276,10 @@ export class DeployService { replication: undefined, trustServerCertificate: undefined, typeSystemVersion: undefined, - workstationId: undefined + workstationId: undefined, + profileName: profile.profileName }; - let connectionUrl = await vscodeMssqlApi.connect(connectionProfile); + let connectionUrl = await vscodeMssqlApi.connect(connectionProfile, saveConnectionAndPassword); return connectionUrl; } else { return undefined; @@ -304,12 +312,12 @@ export class DeployService { return connectionResult ? connectionResult.connectionId : connection; } - public async getConnection(profile: ILocalDbSetting, savePassword: boolean, database: string): Promise { + public async getConnection(profile: ILocalDbSetting, saveConnectionAndPassword: boolean, database: string): Promise { const getAzdataApi = await utils.getAzdataApi(); let connection = await utils.retry( constants.connectingToSqlServerOnDockerMessage, async () => { - return await this.connectToDatabase(profile, savePassword, database); + return await this.connectToDatabase(profile, saveConnectionAndPassword, database); }, this.validateConnection, this.formatConnectionResult, diff --git a/extensions/sql-database-projects/src/typings/vscode-mssql.d.ts b/extensions/sql-database-projects/src/typings/vscode-mssql.d.ts index fe5d89f9d3..d851d28d18 100644 --- a/extensions/sql-database-projects/src/typings/vscode-mssql.d.ts +++ b/extensions/sql-database-projects/src/typings/vscode-mssql.d.ts @@ -54,9 +54,10 @@ declare module 'vscode-mssql' { * Attempts to create a new connection for the given connection info. An error is thrown and displayed * to the user if an error occurs while connecting. * @param connectionInfo The connection info + * @param saveConnection Save the connection profile if sets to true * @returns The URI associated with this connection */ - connect(connectionInfo: IConnectionInfo): Promise; + connect(connectionInfo: IConnectionInfo, saveConnection?: boolean): Promise; /** * Lists the databases for a given connection. Must be given an already-opened connection to succeed.