How to Connect to a Management Group Server

Applies To: System Center Service Manager 2010

To connect to a Service Manager data store, use the EnterpriseManagementGroup class. This class not only connects to the data store but is also your access point for reading and writing information to and from it. The same method of connecting is used whether you are creating a one-time application to accomplish a specific task or a solution that will regularly communicate with the data store.

At minimum, the server you are connecting to must to be specified; localhost can be used when you connect locally. Because the connection that is established is under the credentials of the current process, you can use one of the EnterpriseManagementGroup constructors to specify additional settings for the connection, such as credentials.

To connect to a server with default credentials

  1. Create an instance of the EnterpriseManagementGroup class, specifying the location of the server.

The following example demonstrates how to connect to the server by using default credentials.

EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");

Namespaces

Microsoft.EnterpriseManagement

Assemblies

Microsoft.EnterpriseManagement.Core

To connect to a server

  1. Create an instance of the EnterpriseManagementConnectionSettings class, specifying the location of the server.

  2. Set the UserName, Domain, and Password properties.

  3. Create an instance of the EnterpriseManagementGroup class, passing in the reference to the EnterpriseManagementConnectionSettings class.

The following example demonstrates how to connect to the server by using specific credentials.

EnterpriseManagementConnectionSettings settings = new EnterpriseManagementConnectionSettings("localhost");
settings.UserName = "MyUserName";
settings.Domain = "MyDomain";
settings.Password = new System.Security.SecureString();

foreach (char letter in new char[] { 'M', 'y', 'P', 'a', 's', 's', 'w', 'o', 'r', 'd' })
{
    settings.Password.AppendChar(letter);
}

EnterpriseManagementGroup mg = new EnterpriseManagementGroup(settings);

Namespaces

Microsoft.EnterpriseManagement

Assemblies

Microsoft.EnterpriseManagement.Core

Security

When using the System.Security.SecureString type, make sure that you do not convert a System.String type into a System.Char array type and then use it to fill the Password property. If you do, the password is exposed as plain text in memory when it exists as a String type.