Connect or Disconnect from a Synthesis Repository

Tutorial: Connect and Disconnect from a Synthesis Repository
The following example demonstrates how to connect to a standard Synthesis repository, access one of its projects, and then disconnect from the repository. A discussion of the example follows.

A VBA version of the code sample is available here.

VB.NET SynthesisAPI Module1 Main MyRepository Repository MyRepository.ConnectToRepository ListofProjects NameIdPair ListOfProjects = MyRepository.Project.GetAllProjects MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) ProjectName String ProjectID Integer ProjectName = MyRepository.Project.GetCurrentProject.Name ProjectID = MyRepository.Project.GetCurrentProject.ID   MsgBox ( & ProjectName &  & ProjectID) MyRepository.DisconnectFromRepository

Discussion
The Repository class represents a Synthesis repository. It provides several methods for connecting to either a standard or enterprise repository. In this example, we used the basic ConnectToRepository method to connect to a standard repository. (To connect to an SQL repository, use the ConnectToSQLRepository method. To connect to an Oracle repository, use the ConnectToOracleRepository method.)

Note that to connect successfully, you must at least have "read" permissions in the repository.

MyRepository Repository MyRepository.ConnectToRepository

Once you are connected to a repository, you must specify which of its projects is the current (or active) project. Here, we used the Project.GetAllProjects method to return an array of all the projects in the repository. The method returns a NameIDPair object that represents the name and ID pair of each project.

The Project.SetCurrentProject method is then used to select the desired project. In this case, we've chosen the first project in the array.

Any time you wish to switch to another project in the current repository, use the  method again to specify the new active project. ListofProjects NameIdPair ListOfProjects = MyRepository.Project.GetAllProjects MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) In the following section, we've used the Project.GetCurrentProject method to return the name and ID pair of the current project. ProjectName String ProjectID Integer ProjectName = MyRepository.Project.GetCurrentProject.Name ProjectID = MyRepository.Project.GetCurrentProject.ID  MsgBox ( & ProjectName &  & ProjectID)

Finally, the following code disconnects the session from the current repository.

MyRepository.DisconnectFromRepository