YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Inserting PIValue - ASP .NET Options · View
nunocanas
#1 Posted : Friday, February 04, 2011 2:32:38 PM
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.us

Code 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!

Sponsor  
 

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.
RJK Solutions
#2 Posted : Monday, March 14, 2011 9:50:24 AM
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
be.sule
#3 Posted : Monday, April 11, 2011 12:15:51 PM
Rank: Newbie
Groups: Member

Joined: 2/15/2011
Posts: 7
Hello,

i have the same problem! any ideas?

thx
Darkness
#4 Posted : Wednesday, May 25, 2011 5:08:27 PM
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.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.