AnsweredAssumed Answered

Adding AF Elements using AF SDK

Question asked by natdavidson on Oct 27, 2016
Latest reply on Oct 28, 2016 by Eugene Lee

Hello,

 

I'm pretty new to c#, though i am really eager to learn, i do have experience with VBA.

I'm trying to create an element to a test database, and learn how to adapt this to a production envrionment.

I'm able to connect to the PI server and AF server and find the default AF databases, I then use this code:

            PISystem piSystem = piSystems.DefaultPISystem;

            var db = piSystem.Databases.DefaultDatabase;

            Console.WriteLine("Default Database is {0}", db);

            var Credential = new NetworkCredential("user", "pass", "domain");

 

            piSystem.Connect(Credential);

 

            AFElement element = db.Elements.Add("NateTest");

            element.Description = "Nate's test element";

            element.CheckIn();

 

            piSystem.Disconnect();

 

I get an error saying "An unhandled exception of type 'System.InvalidOperationException' occurred in OSIsoft.AFSDK.dll"

 

Additional information: Database 'Osisoft-test' has been disconnected. This is caused by using an object from a database after calling PISystem.Disconnect.

 

Any help would be appreciated.

Outcomes