Click here to Skip to main content
15,884,177 members
Articles / Web Development / ASP.NET
Tip/Trick

Creating a SQL Server Database Project Use in Visual Studio 2012 and Use TFS for Version Control

Rate me:
Please Sign up or sign in to vote.
4.86/5 (5 votes)
8 Jun 2015CPOL2 min read 26.8K   10  
Creating SQL Server database project use in Visual Studio 2012 and maintain versions use in TFS

Introduction

This article describes how to create SQL Server database project use in Visual Studio 2012 and how to use TFS for version control. It's very important to track database changes and also it helps to identify the new changes in database server.

Background

In large ongoing software projects, normally we use three databases like test, stage and live if we maintain these three databases and add new queries from one database to another, we need to compare databases and also need to identify new changes carefully to do that we can create database projects use in Visual Studio and maintain versions use in TFS.

Using the Code

Go to file, then select -> New -> Project

Image 1

Select SQL server -> then select SQL Server Database Project template.

Image 2

Select Team ->then click Connect to Team Foundation Server option.

Image 3

Select the TFS server you need to connect from dropdown box or click Servers option to add new TFS server.

Image 4

Click Add button for Add new TFS server.

Image 5

Login your Online TFS server use in MICROSOFT account.

Image 6

Add your online TFS server URL then click OK.

Image 7

Then Select server in the dropdown list.

Image 8

Select server from the dropdown list and select Team Project Collection and Team Project you need to connect.

Image 9

Select your project.

Image 10

Now it is ready for Check In.

Image 11

Commit then check In.

Image 12

You can see success message in Team Explorer.

Image 13

Your code in TFS:

Image 14

Now start Generate DB script use in Schema Compare option.

Image 15

Select your target and source for compare.

Image 16

Select your source or Add new Connection.

Image 17

Check connection and add Database for source.

Image 18

Now it displays your source database. Then click ok.

Image 19

Now you can see source is in dropdown now you need to select your target.

Image 20

After selecting target and clicking ok, then it adds to the target dropdown list.

Then click compare option (left side top).

Image 21

It displays your compare details.

Image 22

Click update for add Compare results from source to target.

Image 23

Click ok for confirm.

Image 24

Update starting and it display progress.

Image 25

Now you can checkIn New Changes into TFS.

Image 26

Commit and then Checkin.

Image 27

Now new changes are in TFS.

Image 28

Change your database Store procedure and Check it from VS 2012 compare screen

Image 29

Checkin new Store procedure changes, then it is in TFS.

Image 30

If you need to generate database total script, you need to change project settings.

Select platform and select checkbox in Create script option.

Image 31

Then click publish option for create DB script.

Image 32

Select target database which needs to update from total script.

Image 33

Now your target database details are there.

Image 34

When after click generates Script button, it creates total db script SQL file.

When you execute that SQL script, it will update EyepaxTest database.

Image 35

Finally, it will display execute successful message.

Image 36

Points of Interest

MICROSOFT .NET MAKES LIFE EASY FOR SOFTWARE ENGINEERS. :)

History

  • 07/06/2015: Last update

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer EyepaxIT Consulting Pvt Ltd
Sri Lanka Sri Lanka
I am self motivated team player and Microsoft .Net lover ,past couple of years(more than 5 years) I worked as a Software Engineer .In my life I worked in end to end in SDLC.Currently I am developing applications use in ASP.net MVC ,Sql Server ,WCF/Soap,Rest API,Angular js,Can js and Microsoft Azure(Microsoft cloud)

Comments and Discussions

 
-- There are no messages in this forum --