This seems to be a common problem users are struggling with like illustrated by the following set of forum post. A user creates a database project, imports an existing database, builds and deploys. The resulting script always performs a CREATE DATABASE, why?
The answer is very simple, by default there is no target database connection defined, the deployment detects this and instead of failing, it assumes the target database therefore does not exist and creates a deployment script which will create the database.
Lets walk through the sequence of events:
------ Build started: Project: mydb, Configuration: Debug Any CPU ------ mydb -> d:\users\gert drapers\documents\visual studio 2010\Projects\mydb\sql\debug\mydb.dbschema ------ Deploy started: Project: mydb, Configuration: Debug Any CPU ------ Deployment script generated to: d:\users\gert drapers\documents\visual studio 2010\Projects\mydb\sql\debug\mydb.sql
The deployment script was generated, but was not deployed. You can change the deploy action on the Deploy tab of the project properties. ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ========== ========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========
------ Build started: Project: mydb, Configuration: Debug Any CPU ------ Loading project files... Building the project model and resolving object interdependencies... Validating the project model... Writing model to mydb.dbschema... mydb -> d:\users\gert drapers\documents\visual studio 2010\Projects\mydb\sql\debug\mydb.dbschema ------ Deploy started: Project: mydb, Configuration: Debug Any CPU ------ mydb.dbschema(0,0): Error TSD01234: Before you can deploy a database, you must specify a connection string in the project properties or at a command prompt. Done executing task "SqlDeployTask" -- FAILED. Done building target "DspDeploy" in project "mydb.dbproj" -- FAILED. Done executing task "CallTarget" -- FAILED. Done building target "DBDeploy" in project "mydb.dbproj" -- FAILED. Done building project "mydb.dbproj" -- FAILED.
Build FAILED. ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ========== ========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========
So somewhere hidden inside an error message “Error TSD01234: Before you can deploy a database, you must specify a connection string in the project properties or at a command prompt.”, you will find that the connection string was not defined.
I hope this dissolves one of the common VSDB pitfalls.
GertD @ DBProj.com