Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

PICollectiveMember.Connect Method (String)

  • Last UpdatedNov 18, 2025
  • 5 minute read
PICollectiveMember.Connect Method (String)
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: 3.1.1.1182

Syntax

public void Connect(
	string accessToken
)
Public Sub Connect ( 
	accessToken As String
)

Dim instance As PICollectiveMember
Dim accessToken As String

instance.Connect(accessToken)
public:
void Connect(
	String^ accessToken
)
member Connect : 
        accessToken : string -> unit 

Parameters

accessToken
Type: SystemString
The Access Token to use when connecting to the 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(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;
PICollectiveMember myMember;

// 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
    // Connect and display a credential prompt dialog if current user login fails.
    // Only available in .Net Framework AFSDK
    // myPIServer.Connect(true, null, AFConnectionPreference.RequirePrimary);
    // myPIServer.Disconnect();

    // Connect specifying that Primary is required and display a credential
    // Connect and display a credential prompt dialog if current user login fails.
    // Only available in .Net Framework AFSDK
    // 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.
        myMember = myPIServer.Collective.Members[0];
        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);
}
' Get the PIServers collection for the current user and default PIServer.
Dim myPIServer As PIServer = New PIServers().DefaultPIServer

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

Dim myMember As PICollectiveMember

' Check if default PIServer is a Collective.
If (myPIServer.Collective IsNot Nothing) Then
    ' 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.
    ' Only available in .Net Framework AFSDK
    ' myPIServer.Connect(True, Nothing, AFConnectionPreference.RequirePrimary)
    ' myPIServer.Disconnect()

    ' Connect to a specific collective member and display a credential
    ' Prompt dialog if current user login fails.
    ' Only available in .Net Framework AFSDK
    ' myMember = myPIServer.Collective.Members(0)
    ' myMember.Connect(True, Nothing)
    ' myPIServer.Disconnect()

    Try
        ' Connect to a specific collective member using a specified credential.
        myMember = myPIServer.Collective.Members(0)
        Dim credential As NetworkCredential = New NetworkCredential("guest", String.Empty)
        myMember.Connect(credential)
    Catch ex As Exception
        ' Expected exception since credential needs a valid user name and password.
        Console.WriteLine(ex.Message)
    End Try
End If

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

Version Information

AFSDK

Supported in: 3.1.1, 3.1.0, 3.0.2, 3.0.1, 3.0.0

See Also

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in