Dave Mendlen
Visual Studio
November 1998
Summary: Discusses versioning Microsoft® SQL Server™ 7.0 stored procedures with Visual SourceSafe™ 6.0 and Visual Studio 6.0. (5 printed pages) Covers:
You need to be able to treat your stored procedures the same way you treat the rest of the application that you build with Visual Studio. That means locking up the originals in Visual SourceSafe and versioning them. There are a number of great reasons to use SQL Server 7.0 with Visual SourceSafe, including:
Microsoft Visual InterDev™ and Visual J++™ Setup will automatically install Visual SourceSafe on your client computer. However, for the source control feature to work, you must install the Visual SourceSafe client software on the computer containing your SQL Server.
When you're installing Visual InterDev, make sure to select Visual InterDev Server Setup when this option is offered. This will install the Visual SourceSafe client software on your SQL Server.
In addition, the following procedure will help you set up your SQL Server to use Visual SourceSafe with stored procedures.
When using source control with stored procedures, the SQL Server will be logging into Visual SourceSafe and making the necessary operations on the Visual SourceSafe database. Therefore, it will require appropriate permissions to perform these actions. It is recommended to reduce the security issues by setting the SQL Server service to run as a logged-on user.
To set the SQL server service to run as a logged on user
To add a database to source control
Figure 1. Enable Source Control dialog box
Note The source control database location (the srcsafe.ini file) is relative to your SQL Server database, not to your local computer. In Figure 1, the C: drive and the path shown are on the computer containing the SQL Server database.
To add a new stored procedure to source control
The lock icon is displayed next to the stored procedure. The stored procedure is read from the database and placed in the source control library.
You can check out any of the stored procedures from the database and edit them in your project.
To check out a stored procedure
When you attempt to check out a stored procedure from source control, both the source control version and the database version are retrieved. These versions are then compared. If they are different, you are prompted for which version to use. You can select the database version (and choose to update the source control version), just use the database version, or just use the source control version.
Figure 2. Checking out and editing stored procedures
If you select the source control version, the stored procedure is compiled on the database. If the compile fails, the stored procedure is opened in the editor and marked for editing.
You can also click the View Differences button and see a window displaying the different text for the source control and database versions of the stored procedure.
After you have checked out and edited a stored procedure, you will want to check the changes back into the source control library. When this is done, the stored procedure is read from the database and updated in the source control library. If the stored procedure is open in an editor and marked for editing (as just discussed, the database compile failed when you tried to check the file out), the Check In command is disabled.
To check in a stored procedure
The Check icon next to the stored procedure is removed.
Note You are always working against the database. When you check in a file, the latest database version goes into source control.
You can undo a checkout if you decide you don't want to save your changes.
To undo a checkout
The Check icon next to the stored procedure is removed. The Lock icon is displayed.
When you elect to undo a checkout, an attempt is made to resynchronize the source control library and the database. The previous version from the source control library is compiled on the database. If an error occurs in compiling, no further action is taken and the lock on source control is cleared.
Note In this case, you're getting the source control version, and replacing the version that you have been modifying, because you decided to undo the checkout.
If you get the following dialog box, just type in "Admin" or some other legal user in Visual SourceSafe.
Figure 3. Source Control Login dialog box
Use the Visual Studio/Visual SourceSafe integration with SQL Server 7.0 to ease your ability to work in teams with SQL Server 7.0. Stored procedures are still important in a three-tier world, however you need to ensure that changes made by one developer aren't trampled by those of another or by your database administrator. These tools will ensure that your teams will work more productively.