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

AF SDK Reference

PISystem.ConnectWithPrompt Method

  • Last UpdatedNov 18, 2025
  • 4 minute read
PISystem.ConnectWithPrompt Method
Connects to the server prompting for credentials.

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

Syntax

public void ConnectWithPrompt()
Public Sub ConnectWithPrompt

Dim instance As PISystem

instance.ConnectWithPrompt()
public:
void ConnectWithPrompt()
member ConnectWithPrompt : unit -> unit 

Events

Event TypeReason
PISystemConnectChanged This event will be raised when the connection status for the PISystem changes.

Exceptions

ExceptionCondition
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.

Caution note Caution
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.
Caution note Caution
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.

Version Information

AFSDK

Supported in: 3.1.1, 3.1.0, 3.0.2, 3.0.1, 3.0.0

See Also

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