PISystem.ConnectWithPrompt Method (AFConnectionPreference)
- Last UpdatedNov 18, 2025
- 4 minute read
- PI System
- AF SDK 2024 R2
- Developer
Namespace: OSIsoft.AF
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public void ConnectWithPrompt( AFConnectionPreference preference )
Public Sub ConnectWithPrompt ( preference As AFConnectionPreference ) Dim instance As PISystem Dim preference As AFConnectionPreference instance.ConnectWithPrompt(preference)
public: void ConnectWithPrompt( AFConnectionPreference preference )
member ConnectWithPrompt : preference : AFConnectionPreference -> unit
Parameters
- preference
- Type: OSIsoft.AFAFConnectionPreference
The connection preference to use when determining which member of the AFCollective 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.
Events
| Event Type | Reason |
|---|---|
| PISystemConnectChanged | This event will be raised when the connection status for the PISystem changes. |
Exceptions
| Exception | Condition |
|---|---|
| CommunicationException | The CommunicationException, and any derived class of CommunicationException, are expected exceptions that can be thrown while making a WCF connection from the AF Client to the PI AF Server or if the server reported an error communicating with the SQL Server. The CommunicationException can be expected in any AF SDK method that makes a call to the PI AF Server. |
| TimeoutException | The TimeoutException is an expected exception that can be thrown while making a WCF connection from the AF Client to the AF WCF Server. The exception that is thrown when the time allotted for the connection or operation has expired. The TimoutException can be expected in any AF SDK method that makes a call to the PI AF Server. |
Remarks
The connection to the remote server is established using the ConnectionInfo configuration information. When finished with the connection, the Disconnect method should be called to free resources used by the connection.
If a property or method is called which requires information from the PI AF Server, then a connection will automatically be created to obtain the information. The only exception is the Description property. When not connected, this property will return a string indicating that it is not connected to the server.
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. One of the AFCollectiveMember.Connect Overload methods can be used to connect to a specific server within a AFCollective.
| When calling a connect method and specifying a NetworkCredential as a parameter, all existing connections to the server for the current user will be disconnected. This is done to ensure that the specified credential will be used for the connection to the server for the current user. |
| After connecting to the server, the ID may be updated to match the unique identifier provided by the server. |
Examples
// Get the PISystems collection for the current user and default PISystem. PISystem myPISystem = new PISystems().DefaultPISystem; // Simple connect. myPISystem.Connect(); myPISystem.Disconnect(); // Connect and display a credential prompt dialog if current user login fails. // Only available in .Net Framework AFSDK // myPISystem.Connect(true, null); // myPISystem.Disconnect(); try { // Connect using a specified credential. NetworkCredential credential = new NetworkCredential("guest", String.Empty); myPISystem.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 ' Simple connect. myPISystem.Connect() myPISystem.Disconnect() ' Connect and display a credential prompt dialog if current user login fails. ' Only available in .Net Framework AFSDK ' myPISystem.Connect(True, Nothing) ' myPISystem.Disconnect() Try ' Connect using a specified credential. Dim credential As NetworkCredential = New NetworkCredential("guest", String.Empty) myPISystem.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.