You receive an error message when you get a file from a project label by using OLE automation (196197)



The information in this article applies to:

  • Microsoft Visual SourceSafe for Windows 5.0
  • Microsoft Visual SourceSafe for Windows 6.0

This article was previously published under Q196197

SYMPTOMS

When you use Visual SourceSafe (VSS) OLE automation to get a version of a file based on a project-level label, the following unexpected run-time error might occur:
-2147166583
Version not found.

CAUSE

This problem occurs when you are using a Visual SourceSafe version 5.0 database.

RESOLUTION

Do one of the following to work around this problem:
  • Upgrade the database to the version 6.0 format, which also requires the Visual SourceSafe 6.0 client.
  • Add one extra line of code to your task procedure (see the MORE INFORMATION section of this article for details).

STATUS

This behavior is by design.

MORE INFORMATION

In the Visual SourceSafe Explorer, you can retrieve a particular version of a file based on a project label by viewing the history of that file, selecting the inherited project label, and clicking Get. Alternatively, you can specify the file and the label from the command line.

You can use the following sample Visual Basic code to accomplish the same task by using OLE automation, assuming that the database you are trying to access is in the Visual SourceSafe 6.0 format:
Dim objVSSDB As VSSDatabase
   Dim objVSSFile As VSSItem
   Dim objSpecificVer As VSSItem

   Set objVSSDB = New VSSDatabase

   ' Assign values to the Open method parameters.
   objVSSDB.Open srcsafeini, username, password

   ' Sets file.txt to the object variable.
   Set objVSSFile = objVSSDB.VSSItem("$/Project1/file.txt", False)

   ' Sets the version of file.txt associated with ProjectLabel.
   Set objSpecificVer = objVSSFile.Version("ProjectLabel")
   objSpecificVer.Get "c:\Project1\file.txt"
				
When you access objects in a Visual SourceSafe 5.0 database, you need to add one more line of code. In the above sample, when the objSpecificVer object is set, the .VersionNumber property contains the correct version number of the File.txt based on the project label, assuming that a valid label is sent to the .Version property, but it still contains an invalid object. To work around this, add the following line of code just after you set objSpecificVer and just before you execute the Get method. For example:
   Set objSpecificVer =
   objSpecificVer.Version(objSpecificVer.VersionNumber)
				
This line sets objSpecificVer explicitly by using its own .VersionNumber property, from which the .Version property successfully returns a valid object.

REFERENCES

For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

153925 FAQ: How can I find out if my VSS database has been upgraded?

175758 How to trap Visual SourceSafe OLE errors

For documentation on the Visual SourceSafe OLE automation specification, visit the following Microsoft Developers Network (MSDN) Web site:

Modification Type:MajorLast Reviewed:4/28/2004
Keywords:kbAutomation kbprb KB196197