Sql-server – SSDT publish multiple referenced database projects to new instance

sql serversql-server-2012ssdt

I am going through the process of importing our existing SQL Server databases into SQL Server Data Tools in Visual Studio 2015 with the aim of putting them under version control.

All the database projects in my solution build correctly after splitting databases with circular references into composite projects. My problem is now trying to deploy them all to a new instance, the publishing is failing because the databases being referenced don't exist e.g.

SQL72014: .Net SqlClient Data Provider: Msg 208, Level 16, State 1,
Procedure Foo, Line 13 Invalid object name
'DB1.dbo.Bar'.

If I try to deploy DB1 then it's same thing as that also references another database which hasn't been created yet

SQL72014: .Net SqlClient Data Provider: Msg 208, Level 16, State 1,
Procedure Bar, Line 64 Invalid object name
'DB2.dbo.Foo'

How do I resolve this so I can publish all database projects in my solution to a new instance?

Best Answer

I've been able to get all databases in my solution to publish by doing the following:

  • Setting the correct connection string and publish options under Project Properties > Debug for each project in my solution.
  • Assigning multiple startup projects in Solution Properties
  • Debugging the solution will then build/deploy all databases in the correct order

Though this doesn't feel like it is the correct way to achieve this as it now means I need to modify all my projects if I want to publish to a different server.