Click here to monitor SSC

Product Manager at Red Gate Software. My job is to ensure that the Red Gate SQL tools solve as many development and deployment issues as possible.

SQL Server source control from Visual Studio

Published 30 April 2012 1:16 pm

Developers have long since had to context switch between two IDEs, Visual Studio for application code development and SQL Server Management Studio for database development. While this is accepted, especially given the richness of the database development feature set in SSMS, loading a separate tool can seem a little overkill.

This is where SQL Connect comes in. This is an add-in to Visual Studio that provides a connected development experience for the SQL Server developer. Connected database development involves modifying a development sandbox database, as opposed to offline development, where SQL text files are modified independently of the database. One of the main complaints of Data Dude (VS DBPro) is that it enforces the offline approach. This gripe is what SQL Connect addresses.

If you don’t already use SQL Source Control, you can get up and running with SQL Connect by adding a new project to your Visual Studio solution as follows:

clip_image002

Then choose your existing development database and you’re ready to go.

If you already use SQL Source Control, you will need to link SQL Connect to your existing database scripts folder repository, so SQL Connect and SQL Source Control can be used collaboratively (note that SQL Source Control v.3.0.9.18 or later is required).

Locate the repository (this can be found in the Setup tab in SQL Source Control).

clip_image003

.and create a working folder for it (here I’m using TortoiseSVN).

clip_image004

clip_image005

Back in Visual Studio, locate the SQL Connect panel (in the View menu if it hasn’t auto loaded) and select Import SQL Source Control project

clip_image006

Locate your working folder and click Import.

SQLConnect_SocImport_Improved (2)

This creates a Red Gate database project under your solution:

clip_image008

From here you can modify your development database, and manage your changes in source control. To associate your development database with the project, right click on the project node, select Properties, set the database and Save.

clip_image009

Now you’re ready to make some changes. Locate the object you’d like to modify in the Solution Explorer, and double click it to invoke a query window or table designer. You also have the option to edit the creation SQL directly using Edit SQL File in Project.

clip_image011

Keeping the development database and Visual Studio project in sync is as easy as clicking on a button.

clip_image012

One you’ve made your change, you can use whichever mechanism you choose to commit to source control. Here I’m using the free open-source AnkhSVN to integrate Subversion with Visual Studio.

clip_image013

Maintaining your database in a Visual Studio solution means that you can commit database changes and application code changes in the same changeset. This is desirable if you have continuous integration set up as you want to ensure that all files related to a change are committed atomically, so you avoid an interim “broken build”.

More discussion on SQL Connect and its benefits can be found in the following article on Simple Talk: No More Disconnected SQL Development in Visual Studio

The SQL Connect project team is currently assessing the backlog for the next development effort, and they’d appreciate your feature suggestions, as well as your votes on their suggestions site:

http://redgate.uservoice.com/forums/140800-sql-connect-for-visual-studio-

A 28-day free trial of SQL Connect is available from the Red Gate website.

Technorati Tags:

One Response to “SQL Server source control from Visual Studio”

  1. net performance says:

    I really enjoyed your article. Great posting in your blog make it continue.
    http://www.dapfor.com/en/net-suite/net-grid/features/grid-data-binding

Leave a Reply