"
 
 
 
ASP.NET (snapshot 2017) Microsoft documentation and samples

Deploying Database Projects

by Jason Lee

Download PDF

[!NOTE] In lots of enterprise deployment scenarios, you need the ability to publish incremental updates to a deployed database. The alternative is to recreate the database on every deployment, which means you lose any data in the existing database. When you work with Visual Studio 2010, using VSDBCMD is the recommended approach to incremental database publishing. However, the next version of Visual Studio and the Web Publishing Pipeline (WPP) will include tooling that supports incremental publishing directly.

If you open the Contact Manager sample solution in Visual Studio 2010, you’ll see that the database project includes a Properties folder that contains four files.

Together with the project file (ContactManager.Database.dbproj in this case), these files control various aspects of the build and deployment process:

It’s worth taking a moment to open these files in Visual Studio and familiarize yourself with the contents.

When you build a database project, the build process creates two files:

This shows the relationship between these resources:

As you can see, the .sqlsettings file and the .sqlpermissions file are inputs to the build process. Along with the database project file, these files are used to create the database schema file. The .sqldeployment file and the .sqlcmdvars file pass through the build process unchanged. The deployment manifest indicates the location of the database schema, the .sqldeployment file, the .sqlcmdvars file, and any pre-deployment or post-deployment SQL scripts.

Why Use VSDBCMD to Deploy a Database Project?

There are various different approaches to deploying database projects. However, not all of them are suitable for deploying a database project to remote servers in an enterprise environment. Consider what you want from a database project deployment. In enterprise deployment scenarios, you’re likely to want:

There are three main approaches you can use to deploy a database project:

From this overview, you can see that using VSDBCMD with MSBuild is the approach best suited to a typical enterprise deployment scenario:

Visual Studio 2010 Web Deploy 2.0 VSDBCMD.exe
Supports remote deployment? Yes Yes Yes
Supports incremental updates? Yes No Yes
Supports pre/post-deployment scripts? Yes Yes Yes
Supports multi-environment deployment? Limited Limited Yes
Supports scripted deployment? Limited Yes Yes

The remainder of this topic describes the use of VSDBCMD with MSBuild to deploy database projects.

Understanding the Deployment Process

The VSDBCMD utility lets you deploy a database using either the database schema (the .dbschema file) or the deployment manifest (the .deploymanifest file). In practice, you’ll almost always use the deployment manifest, as the deployment manifest lets you provide default values for various deployment properties and identify any pre-deployment or post-deployment SQL scripts you want to run. For example, this VSDBCMD command is used to deploy the ContactManager database to a database server in a test environment:

[!code-consoleMain]

   1:  vsdbcmd.exe /a:Deploy
   2:              /manifest:"…\ContactManager.Database.deploymanifest"
   3:              /cs:"Data Source=TESTDB1;Integrated Security=true"
   4:              /p:TargetDatabase=ContactManager
   5:              /dd+
   6:              /script:"…\Publish-ContactManager-Db.sql"

In this case:

For more information on VSDBCMD, see Command-Line Reference for VSDBCMD.EXE (Deployment and Schema Import) and How to: Prepare a Database for Deployment From a Command Prompt by Using VSDBCMD.EXE.

For an example of how you can use VSDBCMD from an MSBuild project file, see Understanding the Build Process. For examples of how to configure database deployment settings for multiple environments, see Customizing Database Deployments for Multiple Environments.

Understanding the DeployToDatabase Switch

The behavior of the /dd or /DeployToDatabase switch depends on whether you’re using VSDBCMD with a .dbschema file or a .deploymanifest file. If you’re using a .dbschema file, the behavior is fairly straightforward:

If you’re using a .deploymanifest file, the behavior is a lot more complicated. This is because the .deploymanifest file contains a property name DeployToDatabase that also determines whether the database is deployed.

[!code-xmlMain]

   1:  <DeployToDatabase>False</DeployToDatabase>

The value of this property is set according to the properties of the database project. If you set the Deploy action to Create a deployment script (.sql), the value will be False. If you set the Deploy action to Create a deployment script (.sql) and deploy to the database, the value will be True.

[!NOTE] These settings are associated with a specific build configuration and platform. For example, if you configure settings for the Debug configuration and then publish using the Release configuration, your settings will not be used.

[!NOTE] In this scenario, the Deploy action should always be set to Create a deployment script (.sql), because you don’t want Visual Studio 2010 to deploy your database. In other words, the DeployToDatabase property should always be False.

When a DeployToDatabase property is specified, the /dd switch will only override the property if the property value is false:

Conclusion

This topic provided an overview of the build and deployment process for database projects in Visual Studio 2010. It also described how you can use VSDBCMD.exe with MSBuild to support enterprise-scale database deployment.

For more information on how this works in practice, see Customizing Database Deployments for Multiple Environments.

Further Reading

For information on how to customize database deployments by creating a separate deployment configuration file for each environment, see Customizing Database Deployments for Multiple Environments. For guidance on how to configure database role memberships by running a post-deployment script, see Deploying Database Role Memberships to Test Environments. For guidance on managing some of the unique challenges that membership databases impose, see Deploying Membership Databases to Enterprise Environments.

These topics on MSDN provide broader guidance and background information on Visual Studio database projects and the database deployment process:

Previous Next





Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnet/web-forms/overview/deployment/web-deployment-in-the-enterprise/deploying-database-projects.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>