Reverse Engineer of a .dacpac fails with a Cross-Database Reference
See original GitHub issueI get an error when reverse engineering project with a Database Reference. Dacpac project builds fine and can resolve all objects from referenced database, but reverse engineering fails.
Steps to reproduce
In a dacpac project click Add Database Reference
and reference a dacpac file. It creates a DB variable, for example, $(DB).
Create a view:
CREATE VIEW [dbo].[View1]
AS
Select * From [$(DB)].dbo.TABLE1
Reverse Engineer error:
System.Exception: Table list error:
Microsoft.SqlServer.Dac.DacServicesException: Cannot save package to file. The model has build blocking errors:
Error SQL71561: Error validating element [dbo].[View1]: SqlView: [dbo].[View1] has an unresolved reference to object [$(DB)].[dbo].[TABLE1].
at Microsoft.SqlServer.Dac.Model.SqlSchemaModelObjectService.ValidateAndThrowOnErrors(Boolean treatWarningsAsErrors, IEnumerable`1 ignoreValidationErrors)
at Microsoft.SqlServer.Dac.Model.SqlSchemaModelObjectService.BuildPackage(Func`1 streamGetter, PackageMetadata packageMetadata, PackageOptions packageOptions)
at Microsoft.SqlServer.Dac.Model.TSqlModel.BuildPackage(String packageFilePath, PackageMetadata packageMetadata, PackageOptions packageOptions)
at Microsoft.SqlServer.Dac.DacPackageExtensions.BuildPackage(String packageFilePath, TSqlModel model, PackageMetadata packageMetadata)
at ReverseEngineer20.DacpacConsolidate.DacpacMerger.WriteFinalDacpac(TSqlModel model, String preScript, String postScript) in C:\Code\EFCorePowerTools\src\GUI\ErikEJ.EntityFrameworkCore.SqlServer.Dacpac\DacpacConsolidate\DacpacMerger.cs:line 86
at ReverseEngineer20.DacpacConsolidate.DacpacMerger.Merge() in C:\Code\EFCorePowerTools\src\GUI\ErikEJ.EntityFrameworkCore.SqlServer.Dacpac\DacpacConsolidate\DacpacMerger.cs:line 78
at ReverseEngineer20.DacpacConsolidate.DacpacConsolidator.Consolidate(String dacpacPath) in C:\Code\EFCorePowerTools\src\GUI\ErikEJ.EntityFrameworkCore.SqlServer.Dacpac\DacpacConsolidate\DacpacConsolidator.cs:line 26
at ReverseEngineer20.DacpacTableListBuilder.GetTableDefinitions() in C:\Code\EFCorePowerTools\src\GUI\ErikEJ.EntityFrameworkCore.SqlServer.Dacpac\DacPacEngine\DacpacTableListBuilder.cs:line 32
at efreveng.Program.BuildDacpacList(String dacpacPath) in C:\Code\EFCorePowerTools\src\GUI\efreveng\Program.cs:line 94
at efreveng.Program.Main(String[] args) in C:\Code\EFCorePowerTools\src\GUI\efreveng\Program.cs:line 21
at EFCorePowerTools.Handlers.ReverseEngineer.ResultDeserializer.BuildTableResult(String output) in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineer\ResultDeserializer.cs:line 47
at ReverseEngineer20.ReverseEngineer.EfRevEngLauncher.GetTablesInternal(String arguments) in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineer\EfRevEngLauncher.cs:line 64
at ReverseEngineer20.ReverseEngineer.EfRevEngLauncher.GetDacpacTables(String dacpacPath) in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineer\EfRevEngLauncher.cs:line 30
at EFCorePowerTools.Handlers.ReverseEngineer.TableListBuilder.GetTableDefinitions(Boolean useEFCore5) in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineer\TableListBuilder.cs:line 33
at EFCorePowerTools.Handlers.ReverseEngineerHandler.GetDacpacTables(String dacpacPath, Boolean useEFCore5) in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 348
at EFCorePowerTools.Handlers.ReverseEngineerHandler.<ReverseEngineerCodeFirst>d__3.MoveNext() in C:\projects\efcorepowertools\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 98
Further technical details
EF Core Power Tools version: 2.4.217
Database engine: SQL Server 2016
Visual Studio version: 16.7.4
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
How to extract a DACPAC with a reference to another ...
I've got a database "[database01]" that I want to extract as a ".dacpac", but since one of my views got a JOIN to...
Read more >Extracting DACPAC even When SQL Server refuses to
The problem starts when you try to extract a DACPAC using SSMS and it fails. The SSMS extraction makes a validation of the...
Read more >Reverse Engineer - Generate from sqlproj doesn't work · ...
The tool attempts to merge all .dacpac into a single one, and for your project, merging either msdb.dacapac or master.dacpac fails. I have ......
Read more >How, and where do I define the cross database references ...
I am working with a project where a code database is referencing a data ... that the dacpac (successfully referenced in VS) is...
Read more >SSDT- How to setup SQL Server Database Project with a ...
I'm trying to create a SQL Server Database project with a database that has cross database queries with multiple databases on the same...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Possibly. Let’s see if any others report this - you are the first one…
Looks like this is not feasible for multiple reasons, workaround is to scaffold from a publish (even local) database.