PICollectiveMember.ConnectDirect Method (Boolean, IWin32Window, Boolean)
- Last UpdatedNov 18, 2025
- 5 minute read
- PI System
- AF SDK 2024 R2
- Developer
Namespace: OSIsoft.AF.PI
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public PIServer ConnectDirect( bool autoPrompt, IWin32Window owner, out bool wasCanceled )
Public Function ConnectDirect ( autoPrompt As Boolean, owner As IWin32Window, <OutAttribute> ByRef wasCanceled As Boolean ) As PIServer Dim instance As PICollectiveMember Dim autoPrompt As Boolean Dim owner As IWin32Window Dim wasCanceled As Boolean Dim returnValue As PIServer returnValue = instance.ConnectDirect(autoPrompt, owner, wasCanceled)
public: PIServer^ ConnectDirect( bool autoPrompt, IWin32Window^ owner, [OutAttribute] bool% wasCanceled )
member ConnectDirect : autoPrompt : bool * owner : IWin32Window * wasCanceled : bool byref -> PIServer
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. - wasCanceled
- Type: SystemBoolean
Returns if the credential dialog prompt was displayed and it was canceled. Otherwise, is returned.
Return Value
Type: PIServerReturns new PIServer that is directly connected to the PICollectiveMember but is independent of the PICollective.
Events
| Event Type | Reason |
|---|---|
| PIServerConnectChanged | This event will be raised when the connection status for the PIServer changes. |
Exceptions
| Exception | Condition |
|---|---|
| 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.
| 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.