Skip to main content

SQL Server Data Tools: Setup Continuous Integration for your Database Projects

In Visual Studio 2013, the SQL Server Data Tools are available out-of-the-box. They give you a new project template, the Database project, that allows you to manage your database objects and scripts in a structured way.

In this post I want to explain how you can enable continuous integration and automatically deploy your database changes each time you check-in some code.

Preparation

Before we start make sure that you created a database project and added some database objects. On your TFS build agent, the SQL Server Data Tools should also be installed. If you are using Visual Studio Online(like I will do) together with a hosted Build Controller, the Data Tools are already installed.(Here is the full list of installed components: http://listofsoftwareontfshostedbuildserver.azurewebsites.net/)

Add a Publish Profile

Open Visual Studio and load your Database Project. Once Visual Studio is ready, right-click on your Database Project and click on Publish…

image

The Publish Database window is loaded. Click on Edit… to add a connection string to the database where you want the database project published to. Afterwards click Save Profile As… to save the Publish profile and add it to your Database Project.

image

As we don’t want to deploy immediately, you can click on Cancel to close the window after the Publish profile is saved.

Creating a new Build Definition

Now everything is configured correctly, it’s time to open up Team Explorer(View –> Team Explorer).

image

Go to the Builds tab to add a new Build Definition.

image

Specify a name for your Build and move on to the Trigger tab.

image

Set the Trigger type to Continuous Integration and jump directly to the Build Defaults tab.

image

On the Build Defaults tab, select the Build Controller where the SQL Server Data Tools are installed. In my case I’m using Visual Studio Online, so I choose the Hosted Build Controller. I also choose to copy the build results to a Drops folder inside source control. Let’s move on to the Process tab.

image

On the Process tab, open up the Advanced section and paste the following line in the MSBuild Arguments field:

/t:build /t:publish /p:SqlPublishProfilePath=NorthwindDBProject.publish.xml

Replace the SqlPublishProfilePath value with the name you choose for your Publish Profile in the Database Project.

image

Save the Build definition, you are done! There are a lot of other things, you can configure, but by default, this should be enough.

Check-in and see what happens…

As a last step, do some changes inside your database project, check them into TFS, and look how your database is rolled out for you…

image

Popular posts from this blog

DevToys–A swiss army knife for developers

As a developer there are a lot of small tasks you need to do as part of your coding, debugging and testing activities.  DevToys is an offline windows app that tries to help you with these tasks. Instead of using different websites you get a fully offline experience offering help for a large list of tasks. Many tools are available. Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator Markdown Preview Graphic Color B

Help! I accidently enabled HSTS–on localhost

I ran into an issue after accidently enabling HSTS for a website on localhost. This was not an issue for the original website that was running in IIS and had a certificate configured. But when I tried to run an Angular app a little bit later on http://localhost:4200 the browser redirected me immediately to https://localhost . Whoops! That was not what I wanted in this case. To fix it, you need to go the network settings of your browser, there are available at: chrome://net-internals/#hsts edge://net-internals/#hsts brave://net-internals/#hsts Enter ‘localhost’ in the domain textbox under the Delete domain security policies section and hit Delete . That should do the trick…

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.