Click or drag to resize
OSIsoft, LLC

PICollectiveMemberConnect Method (NetworkCredential, PIAuthenticationMode)

Directly connects to the specific server within the PICollective using the specified credentials to allow sending and retrieving data.

Namespace:  OSIsoft.AF.PI
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version:
public void Connect(
	NetworkCredential credential,
	PIAuthenticationMode authenticationMode


Type: System.NetNetworkCredential
The NetworkCredential to use when connecting to the server.
Type: OSIsoft.AF.PIPIAuthenticationMode
Specifies the type of authentication to be used when making the connection. The specified credential must match the type of authentication.
Event TypeReason
PIServerConnectChanged This event will be raised when the connection status for the PIServer changes.
InvalidOperationException This exception is thrown if connecting to the collective member is disabled because of it's Priority setting.
PIVersionNotSupportedException This exception will be generated when attempting to connect to a PIServer with using WindowsAuthentication and the server does not support this mode of authentication.

The direct connection to the specific remote server in the PICollective is established using the PICollectiveMember configuration information. This is a direct connection to the collective member that does not provide failover functionality to other collective members. Use one of the ConnectDirect Overload methods to create an independent direct connection to a collective member. When finished with the connection, the PIServer.Disconnect method should be called to free resources used by the connection.

Use the Connect(bool, IWin32Window) method to automatically provide a dialog to prompt for user credentials if the logon fails. Use the Connect(NetworkCredential) method to provide user credentials to be used when connecting to the PIServer.

Important note Important
A direct connection will not failover to another collective member when the current member becomes unavailable. A direct connection will also allow data to be written to the collective member regardless of the AllowWriteValues setting.

// Get the PIServers collection for the current user and default PIServer.
PIServer myPIServer = new PIServers().DefaultPIServer;

// Set default for all connections to be based upon collective member's priority.
PIConnectionInfo.DefaultPreference = AFConnectionPreference.Any;

// Check if default PIServer is a Collective.
if (myPIServer.Collective != null)
    // Simple connect will use Default Preference.

    // Connect specifying that Primary is required and display a credential
    //  prompt dialog if current user login fails.
    myPIServer.Connect(true, null, AFConnectionPreference.RequirePrimary);

    // Connect to a specific collective member and display a credential
    //  prompt dialog if current user login fails.
    PICollectiveMember myMember = myPIServer.Collective.Members[0];
    myMember.Connect(true, null);

        // Connect to a specific collective member using a specified credential.
        NetworkCredential credential = new NetworkCredential("guest", String.Empty);
    catch (Exception ex)
        // Expected exception since credential needs a valid user name and password.

    // Connect to a multipe members of a collective simultaneously using ConnectDirect
    if (myPIServer.Collective.Members.Count > 1)
        PIServer myMemberAsPIServer1 = myPIServer.Collective.Members[0].ConnectDirect();
        PIServer myMemberAsPIServer2 = myPIServer.Collective.Members[1].ConnectDirect();

    Console.WriteLine("PIServer '{0}' is not a collective. No connections were made.", myPIServer.Name);
Version Information


Supported in: 2.10.5, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6
See Also
Enabling Operational Intelligence