Copy element from one AF DB to another

Discussion created by aarloe Employee on May 11, 2010
Latest reply on May 11, 2010 by aarloe



I'm relatively new to AF-SDK programming, but can't seem to find a solution to this problem in the forum or the reference manual. I have 2 AF databases on different servers. I'd like to programatically copy all of the elements that meet some criteria to the other server's database. The code I've got so far is as such:

Dim oPISystems AsNew PISystems
Dim oPISystem As PISystem = oPISystems("AFServer1")
Dim AMI2 As AFDatabase = oPISystem.Databases(span style="color: #a31515;">"AMI2")
Dim oElementList As AFNamedCollection(Of AFElement)

oElementList = AFElement.FindElements(AMI2, Nothing, "SilverSprings*", AFSearchField.Name, True, AFSortField.Name, AFSortOrder.Ascending, 100)

oPISystem = oPISystems("AFServer2")
AMI2 = oPISystem.Databases("AMI2")
Dim oMeterElement As AFElement
Dim MeterMonitorElement As AFElement = AMI2.Elements("MeterMonitor")

For Each oMeterElement In oElementList
     If oMeterElement.Attributes("Active").GetValue.ToString = "Inactive"Then
     End If
Next oMeterElement

Only it fails when I try to add the element from the 1st database to the 2nd database with error:


"Element 'SilverSprings_481516001E' in Element 'Meters' belongs to the 'AMI2' database which does not match the current database 'AMI2'. Parameter name: item"


Do I need to do something special to the element (in this case the oMeterElement) before I add it to the 2nd AF server? Any help is appreciated!