Click or drag to resize
OSIsoft, LLC

PICollectiveMemberConnectDirect Method (NetworkCredential)

Creates an independent direct connection to the specific server of the PICollective using the specified PI User credentials to allow sending and retrieving data for multiple collective members.

Namespace:  OSIsoft.AF.PI
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 2.10.8.440
Syntax
public PIServer ConnectDirect(
	NetworkCredential credential
)

Parameters

credential
Type: System.NetNetworkCredential
The NetworkCredential for the PI User to use when connecting to the server.

Return Value

Type: PIServer
Returns new PIServer that is directly connected to the PICollectiveMember but is independent of the PICollective.
Events
Event TypeReason
PIServerConnectChanged This event will be raised when the connection status for the PIServer changes.
Exceptions
ExceptionCondition
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.
Remarks

A new directly connected PIServer is returned that is created using the PICollectiveMember configuration information and is independent of the PICollective. Since this is a direct connection to the server and is independent of the PICollective, the returned server is not affected by changes to the currently active collective member. This allows values to be written to multiple collective members without needing to change the active collective member. When finished with the connection, the PIServer.Disconnect method should be called to free resources used by the connection.

Use the ConnectDirect(bool, IWin32Window) method to automatically provide a dialog to prompt for user credentials if the logon fails. Use the ConnectDirect(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.

Examples
// 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.
    myPIServer.Connect();
    myPIServer.Disconnect();

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

    // 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);
    myPIServer.Disconnect();

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

    // 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();
        myMemberAsPIServer1.Disconnect();
        myMemberAsPIServer2.Disconnect();
    }

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

AFSDK

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