Control versions of database scripts in 10 simple steps.
The purpose of this article is to empower users with the power of Visual Studio .NET (VS.NET) and Visual Source Safe (VSS). In vast number of projects, .NET code is versioned through VS.NET, but versioning of database scripts is done through traditional use of VSS, i.e., checking out and checking in the files in folders. Maintaining exact versions of scripts in post-implementation support phase and maintenance phase becomes difficult and erroneous if VS.NET is used as a tool for versioning of database scripts. This article shows readers in 10 simple steps to use this very powerful feature of VS.NET.
Create database connections through Visual Studio .NET. Click on ‘View’ in the main menu as shown in fig 1.
On click of ‘Server Explorer’ sub-menu, Server Explorer pane will be displayed with Database Connections and Servers in the tree menu. Right click on Database connections and click ‘Add Connection…’ as shown in fig 2.
Add Connection sub-menu opens a tabbed window. Enter database server name, username, password and database to connect. Also check on the checkbox ‘Allow saving password’ as shown in fig 3.
Message pop up is displayed as shown in fig 4. Click on ‘OK’.
Now, open a blank solution and add a Database project in the Other Projects folder as shown in fig 5.
A pop up will be displayed to choose from database connections already made, or to make new one, add it as a reference to the project. Choose the one on which the scripts are required to be run by clicking on one of them. Refer fig 6.
Database project is added to the solution with two folders Change Script and Queries. Remove these folders and add as per the project requirement. Also add the scripts generated for the tables.
Add the solution to VSS by right-clicking on the solution and clicking on ‘Add Solution to Source Control…’ as shown in fig 8.
Now, open a file and try to edit it. Window to check out the file will open as shown in fig 9. This means that the scripts are now under Source Control.
Any changes to the file are done locally. For the changes to take place on the server, the scripts have to be run on the server. This is done by right clicking on the changed file and clicking on ‘Run’ as shown in fig 10. This will run the scripts on the database, which was added as a reference when creating the project. To run the scripts on some other database, click on ‘Run On…’.
I hope implementation of the 10 simple steps in your future projects saves your time and effort.