reference error to master db when deploying dacpac

63 views Asked by At

I have a database project, containing stored procedures, that access system functionality. For example:

CREATE VIEW [dbo].[viewTest]
AS
    SELECT 
        sk.name as name
        ,sk.key_guid as key_guid      
        FROM sys.symmetric_keys sk
    WHERE name like 'TEST%'

If I do not add master system database reference, this produces an error:

View viewTest contains a not resolved reference...

So I added the master db as system database dependency. In Visual Studio it builds without an error and can also be published from within VS without any issues.

But if I take the created MyDatabase.dacpac and try to publish it via SqlPackage.exe I get reference errors to the master db.

Initializing deployment (Failed)
*** An error occurred during deployment plan generation. Deployment cannot continue.
Error SQL0: The reference to the external element with the name '[master]|[sys].[symmetrickeys]' could not be resolved. No such element exists.

My SlqPackage command was

$SqlPackage /Action:Publish /tsn:"MyDbServer"  /p:TreatVerificationErrorsAsWarnings=True  /tec:False  /tdn:MyDatabase /tu:myUser  /tp:myPassword /sf:"dacpathPath"

I also tried using the publish profile I used in VS

$SqlPackage /Action:Publish /pr:"publish.xml" /sf:"dacpathPath"

but got the same error.

Why does it work in VS but not via SqlPackage.exe? How can I make it work with SqlPackage.exe in order to automate publishing the Db to a given server?

1

There are 1 answers

0
AracKnight On

In case anyone ever stumbles upon this problem, here is what fixed it for me:

Apparently the error message about missing objects in the system database was misleading, the actual error was a referenced .dacpac with an incompatible version accidentally overwriting the correct one when collecting all build outputs into a shared folder.