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

AVEVA Enterprise SCADA High Performance Database (HPDB) API Reference

Iterate through all RealTime tables

This scenario guides you through the steps required to iterate through all the RealTime database (RTDB) tables and the current number of records in each table.

To identify the code associated with each step, see the code comments in the Example code section.

Before you begin

  1. Open the Program.cs file from the created project.
  2. Open the RTDB.
  3. Review the list of additional namespaces needed for the desired scenario.

    using OASySDNA.RealTime.Data.Common.HighPerformanceDBWrapper.Interfaces;
    using OASySDNA.RealTime.Data.Common.HighPerformanceSetDBWrapper;
    using OASySDNA.RealTime.Data.Common.HighPerformanceSetDBWrapper.Interfaces;
    using OASySDNA.RealTime.HighPerformanceDB;
  4. Resolve ambiguous references.

    using RealTimeDatabase = OASySDNA.RealTime.Data.Common.HighPerformanceDBWrapper.RealTimeDatabase;

To iterate through all the tables and their current number of records

  1. Get all the tables in the database.
  2. For each table, process the table collection results by performing the following steps:
    1. Lock the current table for safe reading.
    2. Get the table name and current records in the table.
    3. Unlock the table, if necessary.

Example code

try
{
    IRealTimeDatabase database = new RealTimeDatabase();
    // Open the RTDB.
    if (!database.IsOpen())
    {
        database.Open();
    }
    // Get all the tables in the database.
    RealTimeTablesCollection tables = new RealTimeTablesCollection();
    ITableLockRequestType tableLockRequest = new TableLockRequestType();
    // Process table collection results.
    foreach (RealTimeTable table in tables)
    {
        try
        {
            // Lock the current table for safe reading.
            table.Lock(tableLockRequest.SAFE_READ);
            // Get the table name and current records in the table.
            Console.WriteLine(
quot;Table Name:
{table.Name} has {table.CurrentNumberOfRecords} records."); } finally { // Unlock the table, if necessary. if (table.Locked) { table.UnLock(); } } } } catch (Exception ex) { Console.WriteLine(
quot;Get all tables and number of records failed due to
{ex.Message}"); }
TitleResults for “How to create a CRG?”Also Available in