|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
How to: Prepare Database Build Scripts
After you change the database project, you must prepare the build script to either create or update the target. You specify a new or existing database as the target by configuring build settings in the project properties. After you configure those settings, you can build the database project, which assembles any pre-deployment and post-deployment scripts together with the object definitions from the database project. After you prepare the database build script, you can deploy it to the target's database server.
To prepare a database build script in Visual Studio
In Solution Explorer, click the node for the database project for which you want to prepare a build script.
On the Build menu, click Build DatabaseProject.
The object definition scripts and pre-deployment and post-deployment scripts are assembled. If you are preparing an update script, the target connection that you specified in the build settings determines what updates you must have in order to synchronize the target with the database project.
To prepare a database build script from the command line
Open the Command Prompt window, and browse to your project directory.
By default, projects are created in My Documents/Visual Studio 2005/Projects.
At the command prompt, type the following command line to generate a build script where DatabaseProject is the name of your project:
MSBuild /t:Build Path\DatabaseProject .dbproj
MSBuild.exe must be on the path that your PATH environment variable specifies. In addition, the name of the target database must be set either in the database project or as part of the command line. If you are generating an update script, you must also specify the TargetConnectionString. For more information about command line syntax for generating build scripts, see.
The object definition scripts and pre-deployment and post-deployment scripts are assembled. If you are preparing an update script, the target connection that you specified in the build settings determines what updates you must have in order to synchronize the target with the database project. Results such as the following appear:
Microsoft (R) Build Engine Version 2.0.50727.42
[Microsoft .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation 2005. All rights reserved.
Build started 10/17/2006 10:13:23 AM.
Project "ProjectDrive:\Documents and Settings\UserName\My Documents\Visual Studio 2005\Projects\SolutionName\DatabaseProject\DatabaseProject.dbproj" (build target(s)):
Building deployment script for DatabaseProject : EnableFullTextSearch, BlockIncrementalDeploymentIfDataLoss
. DatabaseProject --> file:///ProjectDrive:/Documents%20and%20Settings/UserName/My%20Documents/Visual%20Studio%202005/Projects/SolutionName/DatabaseProject/sql/DatabaseProject.(local).DatabaseProject.sql
Time Elapsed 00:00:05.95
You can prepare a build script to create a database without having permissions on a target database or server because you do not have to access the database to build the database project for a new deployment. To prepare an update script, you must have permission to access the server, the database, and the database objects in the target.