Click or drag to resize
OSIsoft, LLC

PICollectiveMemberConnect Method (Boolean, IWin32Window)

Directly connects to the specific server within the PICollective with a credential prompt if necessary to allow sending and retrieving data.

Namespace:  OSIsoft.AF.PI
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 2.10.8.440
Syntax
public void Connect(
	bool autoPrompt,
	IWin32Window owner
)

Parameters

autoPrompt
Type: SystemBoolean
If , then a dialog will be displayed to prompt for user credentials if the connection to the server fails. The choice of PIAuthenticationMode in the prompt dialog is only displayed if the AllowExplicit option is set in the AuthenticationOptions setting. When this option is not set, then only WindowsAuthentication is allowed.
owner
Type: System.Windows.FormsIWin32Window
The handle to the window that owns the credential prompt dialog. If , then the owner will be the desktop. This parameter is only used if autoPrompt is and there is a security error when attempting to connect to the PI AF Server.
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

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.

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, 2.5
See Also
Enabling Operational Intelligence