PIServer.ConnectWithPrompt Method (IWin32Window, PIAuthenticationMode, Nullable(AFConnectionPreference))
- Last UpdatedNov 18, 2025
- 4 minute read
- PI System
- AF SDK 2024 R2
- Developer
Open a connection to the PI Data Archive prompting for 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 ConnectWithPrompt( IWin32Window owner, PIAuthenticationMode defaultAuthMode, AFConnectionPreference? preference = null )
Public Sub ConnectWithPrompt ( owner As IWin32Window, defaultAuthMode As PIAuthenticationMode, Optional preference As AFConnectionPreference? = Nothing ) Dim instance As PIServer Dim owner As IWin32Window Dim defaultAuthMode As PIAuthenticationMode Dim preference As AFConnectionPreference? instance.ConnectWithPrompt(owner, defaultAuthMode, preference)
public: void ConnectWithPrompt( IWin32Window^ owner, PIAuthenticationMode defaultAuthMode, Nullable<AFConnectionPreference> preference = nullptr )
member ConnectWithPrompt : owner : IWin32Window * defaultAuthMode : PIAuthenticationMode * ?preference : Nullable<AFConnectionPreference> (* Defaults: let _preference = defaultArg preference null *) -> unit
Parameters
- owner
- Type: System.Windows.FormsIWin32Window
The handle to the window that owns the credential prompt dialog. If , then the owner will be the desktop. - defaultAuthMode
- Type: OSIsoft.AF.PIPIAuthenticationMode
The default PIAuthenticationMode to start with for the authentication mode combo box in the dialog. - preference (Optional)
- Type: SystemNullableAFConnectionPreference
The connection preference to use when determining which member of the PICollective is selected for the connection. The default preference can be obtained from Preference property of the this object's ConnectionInfo. The Preference setting will be updated to this value after a successful connection.
Exceptions
| Exception | Condition |
|---|---|
| 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 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.
If an application accesses a property or invokes a method that requires server access, an implicit connection is performed. When a connection is no longer needed, it can be closed using the Disconnect method.
| When using this method to connect to a PIServer with an explicit login, the AuthenticationOptions order will be ignored. Even if Windows is not listed, the WindowsAuthentication will be attempted if the user selects it. The PIUserAuthentication mode is only allowed when the AllowExplicit option is set in the AuthenticationOptions setting. |
Examples
// Get the PIServers collection for the current user and default PIServer. PIServer myPIServer = new PIServers().DefaultPIServer; // Simple connect. myPIServer.Connect(); myPIServer.Disconnect(); // Connect and display a credential prompt dialog if current user login fails. // Only available in .Net Framework AFSDK // myPIServer.Connect(true, null); // myPIServer.Disconnect(); try { // Connect using a specified credential. NetworkCredential credential = new NetworkCredential("guest", String.Empty); myPIServer.Connect(credential); } catch (Exception ex) { // Expected exception since credential needs a valid user name and password. Console.WriteLine(ex.Message); }
' Get the PIServers collection for the current user and default PIServer. Dim myPIServer As PIServer = New PIServers().DefaultPIServer ' Simple connect. myPIServer.Connect() myPIServer.Disconnect() ' Connect and display a credential prompt dialog if current user login fails. ' Only available in .Net Framework AFSDK ' myPIServer.Connect(True, Nothing) ' myPIServer.Disconnect() Try ' Connect using a specified credential. Dim credential As NetworkCredential = New NetworkCredential("guest", String.Empty) myPIServer.Connect(credential) Catch ex As Exception ' Expected exception since credential needs a valid user name and password. Console.WriteLine(ex.Message) End Try
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.