|
|
Rank: Newbie Groups: Member
Joined: 2/2/2011 Posts: 1 Location: Portugal
|
Good afternoon guys, I'm having a little problem trying to insert new PIValues in ASP .NET. I designed a simple interface in ASP .NET to insert new PIValues. When i try to update the value i get this Exception "Unable to add to a PIValues collection. Failed to clone ValueAttribute" at updatedPIPoint.Data.UpdateValue Method. I tried pretty much everything, am i missing something here? btw this code works on windows forms! Interface -  Uploaded with ImageShack.usCode Behind - Code: protected void btnInsert_Click(object sender, EventArgs e) { string strConnectionString = null; Server _piserver;
PISDKClass myPISDK; myPISDK = new PISDKClass(); strConnectionString = "UID=******;PWD=******; _piserver = myPISDK.Servers["***************"]; _piserver.Open(strConnectionString); if ((!string.IsNullOrEmpty(txtDate.ToString())) && (!string.IsNullOrEmpty(txtValue.ToString()))) { string questionableFormatted; string annotatedFormatted; string substitutedFormatted; PIPoint updatedPIPoint;
PIValue pvValueToAdd = new PIValue(); PITimeFormat ptmTimestamp = new PITimeFormat();
updatedPIPoint = _piserver.PIPoints[txtTag.Text]; ptmTimestamp.LocalDate = new DateTime(2011, 2, 2, 10, 25, 0); //Hard-coded Date
pvValueToAdd.TimeStamp = (PITime)ptmTimestamp; pvValueToAdd.Value = txtValue.Text;
questionableFormatted = "Questionable =" + cbQuestionable.Checked.ToString(); pvValueToAdd.ValueAttributes.LoadFromString(questionableFormatted);
if (!string.IsNullOrEmpty(txtAnnotation.Text)) { annotatedFormatted = "Annotations =" + txtAnnotation.Text; pvValueToAdd.ValueAttributes.LoadFromString(annotatedFormatted); }
substitutedFormatted = "Substituted =" + cbSubstituted.Checked.ToString(); pvValueToAdd.ValueAttributes.LoadFromString(substitutedFormatted);
updatedPIPoint.Data.UpdateValue(pvValueToAdd, 0, DataMergeConstants.dmReplaceDuplicates, null); } } }
Please help the little newbie!
|
|
|
|
|
OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System. We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ or contact OSIsoft vCampus for more details.
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 617 Location: Cheshire, United Kingdom.
|
Hi Nuno, Are you still having issues with this? (Apologies for delay in replying...) Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Newbie Groups: Member
Joined: 2/15/2011 Posts: 7
|
Hello,
i have the same problem! any ideas?
thx
|
|
|
Rank: Newbie Groups: Member
Joined: 5/25/2011 Posts: 4 Location: Belgium
|
I think this issue is related to PI-SDK not being threadsafe for annotations.
I think this used to be a different error in previous versions of PI-SDK, some kind of Crossthreading exception. If it is indeed related to this problem, then the solution would be to execute the code in a thread that has ApartmentState.STA. This includes instantiating the PISKD object in this thread. Your ASP page is running as ApartmentState.MTA.
For performance reasons it might be better to put the PI-SDK code in a webservice that keeps such a thread open and uses the ServerManager object to manage connections to PI servers from different users. This way you can eliminate much delay from connecting to the PI server every time you reload the page.
|
|
|
|
Guest
|