AFCollectiveMember.Connect Method (Boolean, IWin32Window)
- Last UpdatedJan 12, 2026
- 4 minute read
- PI System
- AF SDK 3.2.0
- Developer
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.2.0.7
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 Type | Reason |
|---|---|
| PISystemConnectChanged | This event will be raised when the connection status for the PISystem changes. |
Exceptions
| Exception | Condition |
|---|---|
| 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); } }