7

Is it possible to get VS to drop the destination database before a deploy?

I've tried adding a post deploy script to the project, but it always comes back with active connections.

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
littlechris
  • 4,174
  • 10
  • 43
  • 66

2 Answers2

6

You'll need to look up the Always recreate database option in the properties of the database project -> Deploy -> Deployment configuration file -> Edit Dialog.

Another option "Drop objects that exist in the target database but not in the schema" can also be useful to you.

pylover
  • 7,670
  • 8
  • 51
  • 73
  • Just what I was looking, as always they do it first :) Thanks! – Ignacio Soler Garcia Feb 09 '12 at 18:04
  • Sometimes there's more to it... check last reply of 'noonie' on http://social.msdn.microsoft.com/Forums/en/vstsdb/thread/184af3b8-e24f-4156-8c93-4870aaed039c. "And I've found out why you are getting the drop database in your script. If you have not set a Target connection (or subsequently cleared the previous setting) the deploy process adds the drop & create statements to the .sql file regardless of the setting in the Database.sqldeployment file." – Herman Cordes Jan 24 '13 at 11:00
  • I'm not seeing this in VS 2019. Where is the setting? – William Jockusch Jun 05 '19 at 16:15
1

You should check the Always re-create database option under publish.

DB Project -> Right Click -> Publish -> Advanced

enter image description here

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275