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

AF SDK Reference

PIServer.ConnectWithPrompt Method (AFConnectionPreference)

PIServer.ConnectWithPrompt Method (AFConnectionPreference)

  • Last UpdatedNov 18, 2025
  • 3 minute read
PIServer.ConnectWithPrompt Method (AFConnectionPreference)
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(
	AFConnectionPreference preference
)
Public Sub ConnectWithPrompt ( 
	preference As AFConnectionPreference
)

Dim instance As PIServer
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 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

ExceptionCondition
PIVersionNotSupportedException This exception will be generated when attempting to connect to a PIServer when using this method and the server does not support the OpenIDConnectAuthentication authentication mode.

Remarks

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.

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.

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