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

AF SDK Reference

PICollectiveMember.ConnectDirect Method (NetworkCredential, PIAuthenticationMode)

PICollectiveMember.ConnectDirect Method (NetworkCredential, PIAuthenticationMode)

  • Last UpdatedNov 18, 2025
  • 5 minute read
PICollectiveMember.ConnectDirect Method (NetworkCredential, PIAuthenticationMode)
Creates an independent direct connection to the specific server of the PICollective using the specified credentials to allow sending and retrieving data for multiple collective members.

Namespace:  OSIsoft.AF.PI
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

Syntax

public PIServer ConnectDirect(
	NetworkCredential credential,
	PIAuthenticationMode authenticationMode
)
Public Function ConnectDirect ( 
	credential As NetworkCredential,
	authenticationMode As PIAuthenticationMode
) As PIServer

Dim instance As PICollectiveMember
Dim credential As NetworkCredential
Dim authenticationMode As PIAuthenticationMode
Dim returnValue As PIServer

returnValue = instance.ConnectDirect(credential, 
	authenticationMode)
public:
PIServer^ ConnectDirect(
	NetworkCredential^ credential, 
	PIAuthenticationMode authenticationMode
)
member ConnectDirect : 
        credential : NetworkCredential * 
        authenticationMode : PIAuthenticationMode -> PIServer 

Parameters

credential
Type: System.NetNetworkCredential
The NetworkCredential to use when connecting to the server.
authenticationMode
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.

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(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, 2.10.11, 2.10.5, 2.10.0, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6

See Also

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