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

AF SDK Reference

PISystem.Connect Method (Boolean, IWin32Window, AFConnectionPreference, Boolean)

PISystem.Connect Method (Boolean, IWin32Window, AFConnectionPreference, Boolean)

  • Last UpdatedNov 18, 2025
  • 5 minute read
PISystem.Connect Method (Boolean, IWin32Window, AFConnectionPreference, Boolean)
Connects to the server using the specified connection preference with a credential prompt if necessary to allow sending and retrieving data and return an indication that dialog was canceled.

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

Syntax

public void Connect(
	bool autoPrompt,
	IWin32Window owner,
	AFConnectionPreference preference,
	out bool wasCanceled
)
Public Sub Connect ( 
	autoPrompt As Boolean,
	owner As IWin32Window,
	preference As AFConnectionPreference,
	<OutAttribute> ByRef wasCanceled As Boolean
)

Dim instance As PISystem
Dim autoPrompt As Boolean
Dim owner As IWin32Window
Dim preference As AFConnectionPreference
Dim wasCanceled As Boolean

instance.Connect(autoPrompt, owner, preference, 
	wasCanceled)
public:
void Connect(
	bool autoPrompt, 
	IWin32Window^ owner, 
	AFConnectionPreference preference, 
	[OutAttribute] bool% wasCanceled
)
member Connect : 
        autoPrompt : bool * 
        owner : IWin32Window * 
        preference : AFConnectionPreference * 
        wasCanceled : bool byref -> unit 

Parameters

autoPrompt
Type: SystemBoolean
If , then a dialog will be displayed to prompt for user credentials if the connection to the server fails.
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.
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.
wasCanceled
Type: SystemBoolean
Returns if the credential dialog prompt was displayed and it was canceled. Otherwise, is returned.

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


See Also

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