question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reverse Engineer of a .dacpac fails with a Cross-Database Reference

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikEJcommented, Oct 5, 2020

Possibly. Let’s see if any others report this - you are the first one…

0reactions
ErikEJcommented, Oct 20, 2020

Looks like this is not feasible for multiple reasons, workaround is to scaffold from a publish (even local) database.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found