Database Deployment with the VS 2010 Package/Publish Database Tool-Rachel Appel on Software Development

Share with friends!

  

Database Deployment with the VS 2010 Package/Publish Database Tool

Tags: Deployment, ASP.NET, SQL, IE Developer Tools, Visual Studio 2010

Database deployment hasn't ever been considered the fun part of a developer's job, and automating it to be made easier often takes lots of manual setup.  Earlier versions of Visual Studio didn't have much in the way of deployment built in or easily accessible. Web Deployment Projects, which are a separate download, have no database deployment options (ASP.NET project assets only).  Visual Studio 2010 has incorporated into the IDE a very rich set of web and database deployment configuration settings & tools to make things as easy and automated as possible for developers during the deployment process.

For those of you who are tired of writing SQL scripts to merge schema and data changes will welcome the Package/Publish SQL tool as it presents options to deploy schema only, data and schema, or data only.  Your configuration is also easily saved in source code control, as it's part of the project's settings. Note that at this time, the Package/Publish SQL tool works with SQL Server, SQL Express & SQL Compact, though you can plug in your own providers or use PowerShell Scripts for other non MS SQL databases.

When deploying, you have no dependencies on external tools, though they are accessible - MSDeploy.exe is one example. You don't have to switch from Visual Studio to transfer the files, settings and databases, as the Publish tool will deploy everything automatically.

Package/Publish Database tool settings

To access the deployment tool in Visual Studio 2010 you must first navigate to the project's properties window and find the Package/Publish SQL tab, located just below the Package/Publish Web tab.  Here you will find most everything you'll need for deploying SQL databases.

image

Checking out the options for database deployment in depth...

Just as with the Package/Publish Web tab, the option for build configuration management is at the top of the window.

image

Database connections need to be added to the Database Entries section of the window.  You can add db connections by importing the entries from the Web.config or you can add and remove database connections manually.

Any number of connections is allowed and can be selected for deployment as needed, which is demonstrated in the graphic below. If databases have order dependencies you can prioritize the order by using the up/down arrows along the right side.  Although all entries are checked in the sample below, you only need to check off the ones you want to for deployment purposes.

image

Selecting any single database entry in the list will display the details for that specific database entry in the Database Entry Details panel (in a master-details layout).  Each database entry can contain the following configuration properties:

  • Connection strings for the source and destination databases. 
  • Database deployment options (schema/data/both).
  • Custom .SQL scripts to run.

IMPORTANT: The connection strings in the database entries panel are for the source and destination servers for deployment only.  If you want to configure the connection strings for your application's code to access, use Web.config transforms, which will be deployed with both SQL databases and ASP.NET web assets found in the configuration for the Package/Publish Web tab.

Enter the source and target connection string information as highlighted below (of course, substituting your connection string values where appropriate).

image

Then choose schema/data options and add custom .SQL scripts if you have them.  Notice that there's the auto-generated .sql files that automatically run based on what settings you've chosen and much like the connection string entries above, you can reorder the run sequence of the scripts. There's also room for notes.

image

All Configured and time to deploy

When you deploy using the Publish Web tool it will publish the databases as configured in the Package/Publish Database settings automatically.  There's no need to specify any database settings here as this dialog directs the overall deployment settings (i.e., to & from servers), as well as the publish method (i.e., Web Deploy/FTP/HTTP), target URL, application name & settings, and credentials. 

SNAGHTMLaeca108

Once the overall deployment settings are confirmed, click Publish to kick off the actual deployment! Then verify the deployment by doing one of the following:

  • Create a connection to the deployed database(es) using Visual Studio 2010's Server Explorer then check to ensure the latest versions of database objects & data exist.
  • Investigate the deployment by opening SQL Management Studio and also ensuring correct objects and data have been deployed.
  • Run your deployed app and verify that the changes exist.

Summary

If you're a developer who needs to also put in the time to deploy your own projects - perhaps you're a solo dev or on a small team, then Visual Studio 2010 will be a great companion for you.  VS 2010 makes it easy to deploy SQL databases to test, QA, production or any target environment you want. It's also extensible for those who need to deploy to non-MS SQL databases.

6 Comments

  • Kristen said

    Hi Rachel,

    You don't actually mention where to get this tool from? or if it's part of VS then which edition(s) it's available in?

    From what I can tell it doesn't come with Premier edition which does include database projects.

  • Rachel said

    @Kristen,

    It's the Visual Studio 2010 Package/Publish web tool so it's built into VS. To access it, go to the project's properties.

    This tool is available for ASP.NET projects, so you won't see it in a database project (Pro/Ultimate/etc...doesn't matter, it's the project type)

  • Jeff said

    Wow, excellent post. I note that incredibly your post was duplicated the very next day by Mitesh Madhvani
    at http://miteshmadhvani.wordpress.com/2011/03/28/database-deployment-vs2010/
    where it's titled "Posted: March 28, 2011 by Mitesh in Development". He only left off your "Summary" paragraph, otherwise he copied you verbadum. In any case, love this info, thanks 1^6!

  • Rachel said

    Thanks Jeff. I'm glad you enjoyed reading the post, and thanks for letting me know of the plagiarist too. I'll need to look into that.

    On one hand, imitation is the best form of flattery. On the other hand, the guy just copied this post whole hog without regard to who's IP this is. *sigh* life on the internet.

  • Jason Cusati said

    Hi Rachael,

    Excellent presentation on Tuesday, especially after the quake! Question about deployments for you. Is it possible to deploy database changes that come from database projects in a VS2010 solution? Example: I have a 2008 Database project with schemas stored in it. For my initial deployment package, I would like to use webdeploy from my web project and have it drop, create, and load the data from the database project. Or is it only possible to do database changes with the sql publish tab?

    If that latter is true, do you have recommendations on how best to use the database project in relationship to development tracking and deployments?

    Thanks!
    Jason

  • Rachel said

    Jason,

    As far as I know, you really can't really do that natively in DB projects with the point & click tools (perhaps a DB projs ninja will chip in here with a magic spell that can help).

    You can have msdeploy fire off a bunch of .sql scripts though, which I'm going to guess you may already be doing.

    The team is aware of the need to have a better SQL merging story, so hopefully we'll see some updates in the next release.

    Sorry that's all I have for you at this time. I will be blogging updates as soon as I'm able to speak about the new fetures. We do plan to have more awesome goodies for deployment in the future.

Add a Comment