AFTableConnection Class
- Last UpdatedJan 12, 2026
- 11 minute read
- PI System
- AF SDK 3.2.0
- Developer
The table object allows access to traditional relational database data
through ADO.NET Table Connections.

Inheritance Hierarchy
Namespace: OSIsoft.AF.Asset
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.2.0.7
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
| Name | Description | |
|---|---|---|
| AFTableConnection |
Initializes a new instance of the class with default values.
| |
| AFTableConnection(String) |
Initializes a new instance of the class with the specified name.
| |
| AFTableConnection(String, IDbDataAdapter) |
Overload to create an AFTableConnection using an existing IDbDataAdapter
| |
| AFTableConnection(String, String, Boolean, SecureString) |
Overload to create an AFTableConnection a connection string and optionally a password
|
Properties
| Name | Description | |
|---|---|---|
| CheckOutInfo |
This read-only property returns the checked out status information for the object.
| |
| 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.
| |
| Database |
This read-only property returns the AFDatabase where this object is defined.
| |
| Description |
Read/write property that provides a more detailed description of the object.
| |
| ExternalConnection |
This property retrieves the connection string used to load
externally linked tables.
| |
| ExternalType |
This property retrieves the type of connection to make to the
external database.
| |
| 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.) | |
| Identity |
This read-only property contains identity of the object.
(Inherited from AFObject.) | |
| ImpersonateUser |
This property indicates whether the PI AF Server will impersonate
the client when retrieving an externally persisted table.
| |
| IsDeleted |
This read-only property indicates whether the object has been deleted.
(Inherited from AFObject.) | |
| IsDirty |
This read-only property indicates whether the object has been modified since the
last save to the PI AF Server.
| |
| IsNew |
This read-only property indicates whether the object is new and has never been saved
to the PI AF Server.
| |
| Name |
Read/write property that identifies the name of the object.
| |
| PISystem |
This read-only property allows access to the PISystem associated with this
object.
(Inherited from AFObject.) | |
| ReferenceConnection |
returns connection string for use in an AFTable definition
| |
| SecurePassword |
This property is used to set the password that will be used
with the database connection when impersonation is not used.
| |
| Security |
This read-only property returns the AFSecurity information for the object.
| |
| UniqueID |
Read-only property that provides the object's ID as a String.
(Inherited from AFObject.) |
Methods
| Name | Description | |
|---|---|---|
| ApplyChanges |
This method applies the changes to the object and makes
those changes available to other objects for the current user.
| |
| CheckIn |
This method checks in (commits) all the changes to the object by saving
the information to persistent storage.
| |
| CheckOut |
This method locks the object so that its configuration can be modified.
| |
| CheckOutTableConnections |
Check out the objects with the specified unique identifiers at the specified query date.
| |
| CompareTo(Object) |
Compares this instance with a specified Object.
(Inherited from AFObject.) | |
| CompareTo(AFObject) |
Compares this instance with a specified AFObject.
(Inherited from AFObject.) | |
| DeleteTableConnections |
Delete the objects with the specified unique identifiers.
| |
| Equals(Object) |
Determines whether the specified Object is equal to the current object.
(Inherited from AFObject.) | |
| Equals(AFObject) |
Indicates whether the current object is equal to another object of the same type.
(Inherited from AFObject.) | |
| FindTableConnection |
Retrieves the AFTableConnection object with the specified unique identifier
and the specified version id.
| |
| FindTableConnections(PISystem, Guid) |
Performs a search within the PISystem to retrieve a collection
of AFTableConnection objects with the specified list of unique identifiers.
| |
| 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.
| |
| GetDataAdapter |
Gets the data adapter based on the connection and source string.
| |
| 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.) | |
| GetPath |
Returns the full path to the object, using just the names.
(Inherited from AFObject.) | |
| GetPath(AFObject) |
Returns the path to the object relative from another object.
(Inherited from AFObject.) | |
| 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.) | |
| GetSecurity |
Gets the AFSecurity information of the specified security item
associated with the object.
| |
| GetTableConnectionFromConnectionString |
Return a table connection from a connection string
| |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| LoadTableConnections(IListAFTableConnection) |
Loads the specified list AFTableConnection objects.
| |
| LoadTableConnections(PISystem, Guid) |
Loads the AFTableConnection objects with the specified unique identifiers at
the specified query date.
| |
| Persist |
This method returns the persistence string for the object.
(Inherited from AFObject.) | |
| Refresh |
Refreshes the client with any changes that have been made to the object since loaded.
| |
| ToString |
Returns a String that represents the current object.
(Inherited from AFObject.) | |
| 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
| Name | Description | |
|---|---|---|
| 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();