| Business Application Development with: SQL Server, C#, VB, VB.Net, ASP, ASP.Net, and XML |
|
|
News Links Schedule Site Map Contact |
|
Creating a Daily Visual SourceSafe (VSS) Label with A SQL Agent JobDownload the source code, script
and exec:
As we headed into Maynard to join some of our friends for an evening at a club listening to overly loud music, my wife, Ulli, suggested that we should go with some of these same friends and their kids to one of the local Chinese restaurants that has a buffet. My reply was that I don’t go to buffets. I can’t go to one and then not eat too much. Her reply was that all I needed was “some discipline”. To which I replied that I have discipline enough to not go the buffet in the first place and that was enough discipline to avoid the problem. When it comes to eating, my supply of self discipline goes only so far. I have some more self discipline when it comes to work, but never enough. How about you and your team: Do you have enough? When it comes to self discipline I’ve found it’s always better not to rely on it for very long. Anything that requires discipline should be automated or the team is going to be set up for failures, both small and large. So when I worked in a team recently that was failing to put Visual SourceSafe (VSS) labels on projects after they were checked in we decided to look to automation for a solution. What we cam up with is to continue to require that labels be put on versions of code when major builds where created. But we decided to augment that with automated daily labels. The module that follows handles the job and illustrates how easy it is to use the SourceSafeTypeLib OLE Automation object to work with Visual SourceSafe from .Net. This example is written in VB.Net but it could just as well have been in C# or VB 6.0:
Imports
SourceSafeTypeLib
Module
MakeVSSDailyLabel
'— The SourceSafe INI file.
'— The SourceSafe User ID/Password.
Dim objSourceSafe
As SourceSafeTypeLib.VSSDatabase
'------------------------------------------------------ objSourceSafe = New SourceSafeTypeLib.VSSDatabase
'------------------------------------------------------ objSourceSafe.Open(cSourceSafeINI, cVSSUserName, cVSSPassword)
'------------------------------------------------------ strProject = cVSSRootProject
'------------------------------------------------------
On Error
Resume Next
'------------------------------------------------------ On Error GoTo 0
'------------------------------------------------------
Dim sLabel
As String
objVSSProject = Nothing End Sub End Module The complete solution can be downloaded using the button at the top of this article. If you execute this project it adds a VSS label at the project root, which makes it apply to all projects. The time of day that the label is executed doesn’t matter. Now that we have an easy way to create the label, who’s going to run the program every day without fail? We don’t want to rely on anyone’s discipline so again we turned to automation. The most reliable way to get this program run every day is of course to automate it. There are many programs that will run a program on schedule including Windows’ AT command. For a variety of reasons my favoriate, when available, is SQL Server Agent. Among the reasons that I prefer SQL Server Agent are:
To run a executable in SQL Server Agent every day do the following using SQL Enterprise Manager: · Create a new job with a name that is meaningful such as “VSSDailyLabel” · Add a step with a meaningful such as “Run VSSDailyLabel” o The step’s type should be “Operating System Command (cmnexec) o The command is: “c:\utilities\VSSDailyLabel.exe”. You’ll need to change the path on the command to the path where you’ve saved the executable. · Add a schedule that runs once a day at a time after the programmers have gone home. I pick 11:55 PM. I made the job run only on Monday through Friday to eliminate two extra labels each week. I made a SQL Agent job this way and then scripted it out to a file, “Run VSS Daily Label .sql”, that is in the above download. You should read the script and make changes in several places if you’re going to use it. For starters, you might have to change the path to the VSSDailyLable.exe if you don’t put it into “c:\utilities”. Also you might want to change the owner of the script and you may have to change the server name. Here’s the script:
-- Script generated on 11/22/2004 8:28 AM
BEGIN TRANSACTION
SELECT @ReturnCode = 0
-- Delete the job with the same name (if
it exists) IF (@JobID IS NOT NULL) BEGIN
-- Check if the job is a multi-server job
-- There is, so abort the script
-- Delete the [local] job BEGIN
-- Add the job IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- Add the job steps IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXECUTE @ReturnCode =
msdb.dbo.sp_update_job @job_id = @JobID IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- Add the job schedules IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- Add the Target Servers IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback END
COMMIT TRANSACTION
Having a label a day can sometimes be annoying because there are many labels to wade through. However, every once in a while it proves convenient when we want to extract a build that didn’t get a proper label. Now all I have to work on is my self discipline at the dinner table.
|
|
|
Copyright © 2003-2008 Novick Software, Inc. | Terms of Use | Privacy Policy | Nice Things People Say| |