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

Overwrite a record

This scenario guides you through the steps required to overwrite a record.

For this scenario, you will need to perform the following tasks:

  • Create a local memory record.
  • Change field values.
  • Write the created local record back to the database.

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

To overwrite a record

  1. Open the Program.cs file from the created project.
  2. Open the RealTime database (RTDB).
  3. Lock the analog table for writing.
  4. Find the analog record to get its pointer by name.
  5. Lock the analog record for reading.
  6. Create a local memory record (clone).
  7. Change the name and description of the cloned record.
  8. Overwrite the existing record with the new one.
  9. Unlock the analog record.
  10. Unlock the analog table.

Example code

IRealTimeDatabase database = new RealTimeDatabase();
try
{
       // Open the RTDB.
       if (!database.IsOpen())
       {
           database.Open();
       }
       using (IRealTimeTable table = new RealTimeTable("analog"))
       {
            ITableLockRequestType tableLockRequest = new TableLockRequestType();
            IRecordLockRequestType recordLockRequest = new RecordLockRequestType();
            // Lock the analog table for writing.
            table.Lock(tableLockRequest.SAFE_WRITE);
            // Find the analog record to get its pointer by name.
            var nameField = new RealTimeStringField(table, "name");
            using (var record = table.FindRecord(nameField, "ExtraAnalog"))
            {
                // Lock the analog record for reading.
                record.Lock(recordLockRequest.SAFE_WRITE);
                // Create a local memory record (clone).
                var clonedRec = record.CloneInMemoryCopy();
                // Change the name and description of the cloned record.
                clonedRec.WriteField("description", "Description of cloned record");
                clonedRec.WriteField("name", "ExtraAnalogCloned");
                // Overwrite the existing record with the new one.
                record.WriteRecord((RealTimeBaseRecord)clonedRec);                
                       
            } // Leaving scope releases the analog record lock.
        } // Leaving scope releases the analog table lock.
}
catch (Exception ex)
{
    Console.WriteLine(
quot;Error overwriting the record:
{ex.Message}"); }
TitleResults for “How to create a CRG?”Also Available in