How do you prevent a VS2010 Database Project Deployment from generating a drop database?

1.8k Views Asked by At

Suppose you have a database project and you do NOT have "Always re-create database" checked off in your Database.sqldeployment settings. And suppose you deploy to a server that already has a database by the name of the one you are deploying.

Under what other circumstances will the database deploy generate a script with a "DROP DATABASE" statement?

If you don't ever, ever, ever want your database to be dropped by the deployment script generated by right clicking your database project and selecting "Deploy", what are some of the steps you can take to prevent this?

1

There are 1 best solutions below

1
On

In addition to the "Always re-create database" NOT being checked off, you should also check the Development tab on your database project's Properties page. Make sure you define a target connection. When you don't define one the project will always and only deploy as-if the target database does not exist. This behavior is by design. see this link for more details.

My suggestion is to create the connection using Windows Authentication so each user would have access to the extend they are supposed to.

Also please note that you will have to do this for each Deployment Configuration (e.g. Debug, Release, etc.)

I personally set the deploy action to just create a script and run it manually to be on the safe side!