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

AF SDK Reference

AFCollectiveMember.Connect Method (Boolean, IWin32Window)

AFCollectiveMember.Connect Method (Boolean, IWin32Window)

  • Last UpdatedNov 18, 2025
  • 4 minute read
AFCollectiveMember.Connect Method (Boolean, IWin32Window)
Connects to the specific server within the AFCollective with a credential prompt if necessary to allow sending and retrieving data.

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

Syntax

public void Connect(
	bool autoPrompt,
	IWin32Window owner
)
Public Sub Connect ( 
	autoPrompt As Boolean,
	owner As IWin32Window
)

Dim instance As AFCollectiveMember
Dim autoPrompt As Boolean
Dim owner As IWin32Window

instance.Connect(autoPrompt, owner)
public:
void Connect(
	bool autoPrompt, 
	IWin32Window^ owner
)
member Connect : 
        autoPrompt : bool * 
        owner : IWin32Window -> unit 

Parameters

autoPrompt
Type: SystemBoolean
If , then a dialog will be displayed to prompt for user credentials if the connection to the server fails.
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
PISystemConnectChanged This event will be raised when the connection status for the PISystem changes.

Exceptions

ExceptionCondition
InvalidOperationException This exception is thrown if connecting to the collective member is disabled because of it Priority setting.

Remarks

The connection to the specific remote server in the AFCollective is established using the AFCollectiveMember configuration information. When finished with the connection, the PISystem.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 PISystem.

Examples

// Get the PISystems collection for the current user and default PISystem.
PISystem myPISystem = new PISystems().DefaultPISystem;

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

// Simple connect will use Default Preference.
myPISystem.Connect();
myPISystem.Disconnect();

// Check if default PISystem is a Collective.
if (myPISystem.Collective != null)
{
    // 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
    // myPISystem.Connect(true, null, AFConnectionPreference.RequirePrimary);
    // myPISystem.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.
    // myMember = myPISystem.Collective.Members[0];
    // myMember.Connect(true, null);
    // myPISystem.Disconnect();

    try
    {
        // Connect to a specific collective member using a specified credential.
        myMember = myPISystem.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);
    }
}
' Get the PISystems collection for the current user and default PISystem.
Dim myPISystem As PISystem = New PISystems().DefaultPISystem

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

Dim myMember As AFCollectiveMember

' Simple connect will use Default Preference.
myPISystem.Connect()
myPISystem.Disconnect()

' Check if default PISystem is a Collective.
If (myPISystem.Collective IsNot Nothing) Then
    ' Connect specifying that Primary is required and display a credential
    ' Prompt dialog if current user login fails.
    ' Only available in .Net Framework AFSDK
    ' myPISystem.Connect(True, Nothing, AFConnectionPreference.RequirePrimary)
    ' myPISystem.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 = myPISystem.Collective.Members(0)
    ' myMember.Connect(True, Nothing)
    ' myPISystem.Disconnect()

    Try
        ' Connect to a specific collective member using a specified credential.
        myMember = myPISystem.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


See Also

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