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

AF SDK Reference

PIServer.Connect Method (NetworkCredential)

  • Last UpdatedJan 12, 2026
  • 2 minute read
PIServer.Connect Method (NetworkCredential)
Open a connection to the PI Data Archive using the specified PI User credentials to allow sending and retrieving data.

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

Syntax

public void Connect(
	NetworkCredential credential
)
Public Sub Connect ( 
	credential As NetworkCredential
)

Dim instance As PIServer
Dim credential As NetworkCredential

instance.Connect(credential)
public:
void Connect(
	NetworkCredential^ credential
)
member Connect : 
        credential : NetworkCredential -> unit 

Parameters

credential
Type: System.NetNetworkCredential
The NetworkCredential for the PI User to use when connecting to the server.

Exceptions

ExceptionCondition
PIConnectionExceptionA connection to the PI Data Archive server cannot be made.

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);
}

Version Information

AFSDK


See Also

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