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

AF SDK Reference

AFTableConnection Class

  • Last UpdatedNov 18, 2025
  • 13 minute read
AFTableConnection Class
The table object allows access to traditional relational database data through ADO.NET Table Connections.

Inheritance Hierarchy

SystemObject
  OSIsoft.AFAFObject
    OSIsoft.AF.AssetAFTableConnection

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

Syntax

[SerializableAttribute]
public sealed class AFTableConnection : AFObject, 
	IAFTransactable, IAFChangedEvent, IAFSecurable, IComparable<AFTableConnection>
<SerializableAttribute>
Public NotInheritable Class AFTableConnection
	Inherits AFObject
	Implements IAFTransactable, IAFChangedEvent, IAFSecurable, IComparable(Of AFTableConnection)

Dim instance As AFTableConnection
[SerializableAttribute]
public ref class AFTableConnection sealed : public AFObject, 
	IAFTransactable, IAFChangedEvent, IAFSecurable, IComparable<AFTableConnection^>
[<SealedAttribute>]
[<SerializableAttribute>]
type AFTableConnection =  
    class
        inherit AFObject
        interface IAFTransactable
        interface IAFChangedEvent
        interface IAFSecurable
        interface IComparable<AFTableConnection>
    end

The AFTableConnection type exposes the following members.

Constructors

  NameDescription
Public method
AFTableConnection
Initializes a new instance of the class with default values.
Public method
AFTableConnection(String)
Initializes a new instance of the class with the specified name.
Public method
AFTableConnection(String, IDbDataAdapter)
Overload to create an AFTableConnection using an existing IDbDataAdapter
Public method
AFTableConnection(String, String, Boolean, SecureString)
Overload to create an AFTableConnection a connection string and optionally a password

Properties

  NameDescription
Public property
CheckOutInfo
This read-only property returns the checked out status information for the object.
Public property
Command
This property is a SQL command or query used when the AFTableConnection is used in place of an IDbAdapter in an AFTable. It is not persisted.
Public property
Database
This read-only property returns the AFDatabase where this object is defined.
Public property
Description
Read/write property that provides a more detailed description of the object.
Public property
ExternalConnection
This property retrieves the connection string used to load externally linked tables.
Public property
ExternalType
This property retrieves the type of connection to make to the external database.
Public property
ID
Read-only property that provides a unique identifier for the object to be used for quick access that is not dependent upon the index.
(Inherited from AFObject.)
Public property
Identity
This read-only property contains identity of the object.
(Inherited from AFObject.)
Public property
ImpersonateUser
This property indicates whether the PI AF Server will impersonate the client when retrieving an externally persisted table.
Public property
IsDeleted
This read-only property indicates whether the object has been deleted.
(Inherited from AFObject.)
Public property
IsDirty
This read-only property indicates whether the object has been modified since the last save to the PI AF Server.
Public property
IsNew
This read-only property indicates whether the object is new and has never been saved to the PI AF Server.
Public property
Name
Read/write property that identifies the name of the object.
Public property
PISystem
This read-only property allows access to the PISystem associated with this object.
(Inherited from AFObject.)
Public property
ReferenceConnection
returns connection string for use in an AFTable definition
Public property
SecurePassword
This property is used to set the password that will be used with the database connection when impersonation is not used.
Public property
Security
This read-only property returns the AFSecurity information for the object.
Public property
UniqueID
Read-only property that provides the object's ID as a String.
(Inherited from AFObject.)

Methods

  NameDescription
Public methodCode example
ApplyChanges
This method applies the changes to the object and makes those changes available to other objects for the current user.
Public methodCode example
CheckIn
This method checks in (commits) all the changes to the object by saving the information to persistent storage.
Public method
CheckOut
This method locks the object so that its configuration can be modified.
Public methodStatic member
CheckOutTableConnections
Check out the objects with the specified unique identifiers at the specified query date.
Public method
CompareTo(Object)
Compares this instance with a specified Object.
(Inherited from AFObject.)
Public method
CompareTo(AFObject)
Compares this instance with a specified AFObject.
(Inherited from AFObject.)
Public methodStatic member
DeleteTableConnections
Delete the objects with the specified unique identifiers.
Public method
Equals(Object)
Determines whether the specified Object is equal to the current object.
(Inherited from AFObject.)
Public method
Equals(AFObject)
Indicates whether the current object is equal to another object of the same type.
(Inherited from AFObject.)
Public methodStatic member
FindTableConnection
Retrieves the AFTableConnection object with the specified unique identifier and the specified version id.
Public methodStatic member
FindTableConnections(PISystem, Guid)
Performs a search within the PISystem to retrieve a collection of AFTableConnection objects with the specified list of unique identifiers.
Public methodStatic member
FindTableConnections(AFDatabase, String, AFSearchField, AFSortField, AFSortOrder, Int32)
Performs a text search within the AFDatabase to retrieve a collection of AFTableConnection objects that match the specified query string.
Public methodStatic member
GetDataAdapter
Gets the data adapter based on the connection and source string.
Public method
GetHashCode
Gets the hash code for this instance of the object which is suitable for use in hashing algorithms and data structures like a hash table.
(Inherited from AFObject.)
Public method
GetPath
Returns the full path to the object, using just the names.
(Inherited from AFObject.)
Public method
GetPath(AFObject)
Returns the path to the object relative from another object.
(Inherited from AFObject.)
Public method
GetPath(AFEncodeType, AFObject)
Returns the path to the object relative from another object, using the name and/or id as specified by encodeType.
(Inherited from AFObject.)
Public method
GetSecurity
Gets the AFSecurity information of the specified security item associated with the object.
Public methodStatic member
GetTableConnectionFromConnectionString
Return a table connection from a connection string
Public method
GetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic member
LoadTableConnections(IListAFTableConnection)
Loads the specified list AFTableConnection objects.
Public methodStatic member
LoadTableConnections(PISystem, Guid)
Loads the AFTableConnection objects with the specified unique identifiers at the specified query date.
Public method
Persist
This method returns the persistence string for the object.
(Inherited from AFObject.)
Public method
Refresh
Refreshes the client with any changes that have been made to the object since loaded.
Public method
ToString
Returns a String that represents the current object.
(Inherited from AFObject.)
Public method
UndoCheckOut
This method discards all the changes to the object and all sub-objects since the last call to CheckOut. Any changes since the check out will be lost.

Events

  NameDescription
Public eventCode example
Changed
Event is raised when the object or one of its sub-objects is changed.

Remarks

A table connection is used by an AFTable to configure the information required to establish a connection to a linked table.

Examples

// This example demonstrates how to link an existing external table to an AFTable with an
// AFTableConnection configured to use an ADODB.Recordset and three .NET data adapters (ODBC,
// OLEDB, and SQL). The link to the SQL Server table is configured to use parameters.
// Note: This sample uses a sample MS Access 2010 database that can be downloaded from Microsoft at:
// http://office.microsoft.com/en-us/templates/northwind-sales-web-database-TC101114818.aspx

// This example will work with 64 bit Microsoft Office 2010 and SQL Server 2012 - some 
// modifications to connection strings will be necessary to work with other versions
// of Microsoft Office and Microsoft SQL Server or on 32 bit systems.

// Get the Database 
PISystems myPISystems = new PISystems();
AFDatabase myDB = myPISystems.DefaultPISystem.Databases.DefaultDatabase;

// Create the parameters used in the table query
Dictionary<string, object> myParameters = new Dictionary<string, object>();
myParameters.Add("@City", "London");

// Create the password used when connecting to the external table
System.Security.SecureString password = new System.Security.SecureString();
foreach (char c in SqlPassword)
{
    password.AppendChar(c);
}

password.MakeReadOnly();

// ****************************************************
// Create a Table Connection using an OLEDB data adapter
// ****************************************************
AFTableConnection myConnection = myDB.TableConnections.Add("Employees OLEDB");
myConnection.Description = "This is my employee table connection using OLEDB data adapter.";
myConnection.ImpersonateUser = true;
myConnection.ExternalConnection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Northwind.accdb";
myConnection.ExternalType = typeof(OleDbDataAdapter).FullName;
myConnection.CheckIn();

// Create a Table and Link to the External Table using the OLEDB data adapter Table Connection
AFTable myTable = myDB.Tables.Add("Employees OLEDB");
myTable.Description = "This is my employee table using OLEDB data adapter.";
myTable.CacheInterval = TimeSpan.FromMinutes(30);
myTable.LinkExternal(myConnection, "SELECT * FROM Employees", null);
myTable.CheckIn();

// ***************************************************
// Create a Table Connection from Excel using an ODBC data adapter
// ***************************************************
myConnection = myDB.TableConnections.Add("Employees ODBC");
myConnection.Description = "This is my employee table connection using ODBC data adapter.";
myConnection.ImpersonateUser = true;
myConnection.ExternalConnection = @"DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=\Employees.xlsx";
myConnection.ExternalType = typeof(OdbcDataAdapter).FullName;

// Create a Table and Link to the External Table using the ODBC data adapter Table Connection
myTable = myDB.Tables.Add("Employees ODBC");
myTable.Description = "This is my employee table from Excel using ODBC data adapter.";
myTable.CacheInterval = TimeSpan.FromMinutes(30);
myTable.LinkExternal(myConnection, "SELECT * FROM A1:F10", null);
myTable.CheckIn();

// *************************************************
// Create a Table Connection using a SQL data adapter
// *************************************************
myConnection = myDB.TableConnections.Add("Employees SQL");
myConnection.Description = "This is my employee table connection using SQL data adapter.";
myConnection.ExternalConnection = $"Server={SqlServerMachineName};Database=Northwind;User Id={SqlUserId};Password=<PASSWORD>;Trusted_Connection=False;";
myConnection.ExternalType = typeof(SqlDataAdapter).FullName;
myConnection.SecurePassword = password;

// Create a Table and Link to the External Table using the SQL data adapter Table Connection
myTable = myDB.Tables.Add("Employees SQL");
myTable.Description = "This is my employee table using SQL data adapter.";
myTable.CacheInterval = TimeSpan.FromMinutes(30);
myTable.LinkExternal(myConnection, "SELECT * FROM Employees WHERE [City] = @City", myParameters);
myTable.CheckIn();

// Display the DataTable using Parameters
myParameters = new Dictionary<string, object>();
myParameters.Add("@City", "Seattle");
DataTable table = myTable.GetTableWithParameters(myParameters);
StringBuilder line = new StringBuilder();
foreach (DataColumn col in table.Columns)
{
    line.AppendFormat("{0}, ", col.ColumnName);
}
Console.WriteLine(line.ToString());
line.Clear();
foreach (DataRow row in table.Rows)
{
    foreach (DataColumn col in table.Columns)
    {
        line.AppendFormat("{0}, ", row[col.ColumnName]);
    }
    Console.WriteLine(line.ToString());
    line.Clear();
}

// The Table can be Refreshed Manually using AFTable.Refresh
myTable.Refresh();
' This example demonstrates how to link an existing external table to an AFTable using an ADODB.Recordset
' AFTableConnection configured to use an ADODB.Recordset and three .NET data adapters (ODBC,
' OLEDB, and SQL). The link to the SQL Server table is configured to use parameters.
' Note: This sample uses a sample MS Access 2010 database that can be downloaded from Microsoft at:
' http://office.microsoft.com/en-us/templates/northwind-sales-web-database-TC101114818.aspx

' This example will work with 64 bit Microsoft Office 2010 and SQL Server 2012 - some 
' modifications to connection strings will be necessary to work with other versions
' of Microsoft Office and Microsoft SQL Server or on 32 bit systems.

' Get the Database 
Dim myPISystems As New PISystems
Dim myDB As AFDatabase = myPISystems.DefaultPISystem.Databases.DefaultDatabase

' Create the parameters used in the table query
Dim myParameters As New Dictionary(Of String, Object)()
myParameters.Add("@City", "London")

' Create the password used when connecting to the external table
Dim password As System.Security.SecureString = New System.Security.SecureString
For Each c As Char In SqlPassword
    password.AppendChar(c)
Next

password.MakeReadOnly()

' ****************************************************
' Create a Table Connection using an OLEDB data adapter
' ****************************************************
Dim myConnection As AFTableConnection = myDB.TableConnections.Add("Employees OLEDB")
myConnection.Description = "This is my employee table connection using OLEDB data adapter."
myConnection.ImpersonateUser = True
myConnection.ExternalConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Northwind.accdb"
myConnection.ExternalType = GetType(OleDbDataAdapter).FullName
myConnection.CheckIn()

' Create a Table and Link to the External Table using the OLEDB data adapter Table Connection
Dim myTable As AFTable = myDB.Tables.Add("Employees OLEDB")
myTable.Description = "This is my employee table using OLEDB data adapter."
myTable.CacheInterval = TimeSpan.FromMinutes(30)
myTable.LinkExternal(myConnection, "SELECT * FROM Employees", Nothing)
myTable.CheckIn()

' ***************************************************
' Create a Table Connection from Excel using an ODBC data adapter
' ***************************************************
myConnection = myDB.TableConnections.Add("Employees ODBC")
myConnection.Description = "This is my employee table connection using ODBC data adapter."
myConnection.ImpersonateUser = True
myConnection.ExternalConnection = "DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=\Employees.xlsx"
myConnection.ExternalType = GetType(OdbcDataAdapter).FullName

' Create a Table and Link to the External Table using the ODBC data adapter Table Connection
myTable = myDB.Tables.Add("Employees ODBC")
myTable.Description = "This is my employee table from Excel using ODBC data adapter."
myTable.CacheInterval = TimeSpan.FromMinutes(30)
myTable.LinkExternal(myConnection, "SELECT * FROM A1:F10", Nothing)
myTable.CheckIn()

' *************************************************
' Create a Table Connection using a SQL data adapter
' *************************************************
myConnection = myDB.TableConnections.Add("Employees SQL")
myConnection.Description = "This is my employee table connection using SQL data adapter."
myConnection.ExternalConnection = $"Server={SqlServerMachineName};Database=Northwind;User Id={SqlUserId};Password=<PASSWORD>;Trusted_Connection=False;"
myConnection.ExternalType = GetType(SqlDataAdapter).FullName
myConnection.SecurePassword = password

' Create a Table and Link to the External Table using the SQL data adapter Table Connection
myTable = myDB.Tables.Add("Employees SQL")
myTable.Description = "This is my employee table using SQL data adapter."
myTable.CacheInterval = TimeSpan.FromMinutes(30)
myTable.LinkExternal(myConnection, "SELECT * FROM Employees WHERE [City] = @City", myParameters)
myTable.CheckIn()

' Display the DataTable using Parameters
myParameters = New Dictionary(Of String, Object)()
myParameters.Add("@City", "Seattle")
Dim table As DataTable = myTable.GetTableWithParameters(myParameters)
Dim line As New StringBuilder()
For Each col As DataColumn In table.Columns
    line.AppendFormat("{0}, ", col.ColumnName)
Next
Console.WriteLine(line.ToString())
line.Clear()
For Each row As DataRow In table.Rows
    For Each col As DataColumn In table.Columns
        line.AppendFormat("{0}, ", row(col.ColumnName))
    Next
    Console.WriteLine(line.ToString())
    line.Clear()
Next

' The Table can be Refreshed Manually using AFTable.Refresh
myTable.Refresh()

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, 2.10.11, 2.10.5, 2.10.0, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6

See Also

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