diff --git a/extensions/sql-database-projects/src/models/project.ts b/extensions/sql-database-projects/src/models/project.ts index 527174223c..5aca304079 100644 --- a/extensions/sql-database-projects/src/models/project.ts +++ b/extensions/sql-database-projects/src/models/project.ts @@ -435,6 +435,12 @@ export class Project { */ public async addProjectReference(settings: IProjectReferenceSettings): Promise { const projectReferenceEntry = new SqlProjectReferenceProjectEntry(settings); + + // check if reference to this database already exists + if (this.databaseReferenceExists(projectReferenceEntry)) { + throw new Error(constants.databaseReferenceAlreadyExists); + } + await this.addToProjFile(projectReferenceEntry); } @@ -621,7 +627,7 @@ export class Project { } private databaseReferenceExists(entry: IDatabaseReferenceProjectEntry): boolean { - const found = this.databaseReferences.find(reference => reference.fsUri.fsPath === entry.fsUri.fsPath) !== undefined; + const found = this.databaseReferences.find(reference => reference.pathForSqlProj() === entry.pathForSqlProj()) !== undefined; return found; }