7 Replies Latest reply on May 18, 2016 11:53 AM by pthivierge

    Connect PI Data Archive via PI ACE code

    Paurav Joshi

      We are trying to connect to PI Data Archive, in PI ACE code.

       

      Code snippet is as follows:

      Dim myPIServers As PIServers = New PIServers
      Dim myPIDataArchive As PIServer = myPIServers("<PI_Data_Archive_name>")
      

       

      When we debug the ACE code, at that time we found that the value of PIDataArchive is coming as "PIServer {93} Becasue this evaluation could cause side effects, it will not be executed untill enabled by user" .

       

      We can connect to Data Archive via PI SMT and it is connecting as piadmin, so we doubt that there is access issue.

       

      I know we are missing something, but unable to figure out that. These are two different machines, one is PI Data Archive and the other is on which the code is running.

       

      Do anybody goes through via same hurdle?

       

      Thanks,

      Paurav Joshi

        • Re: Connect PI Data Archive via PI ACE code
          pthivierge

          Hello Paurav,

           

          With this code you are only getting the server object, you are not connecting. To make the connection you need to call the connect method e.g.:

          ' gets the PI Server (PI Data Archive)
           Dim server = PIServer.FindPIServer(servername)
          
          If server = Nothing Then
           Throw New NullReferenceException("The specified PI Server could not be found")
          End If
          
          server.Connect()
          

           

          Do you have enabled connections by trust or by windows authentication on the client?

          (PI SDK Utility, Connections, Options)

           

          Then make sure to add logging to your ACE application, so you understand what is happening.

          Logging capabilities in PI Advanced Computing Engine (PI ACE)

           

          Let us know if this helps,

            • Re: Connect PI Data Archive via PI ACE code
              Paurav Joshi

              Thanks Patrice Thivierge .

               

              We already enabled debugging, and we are connecting via trust, so I think connect method explicitly is not needed.

              Code is running fine and we are getting correct output, but we are still unable to understand the weird value of PI Data Archive as well as PI tag.

               

              Thanks,

              Paurav Joshi

                • Re: Connect PI Data Archive via PI ACE code
                  pthivierge

                  Hello Paurav,

                   

                  If you are not calling the connect explicitely, the AF SDK will have to call it implicitely later on for you, and this is one of the reason that you see this message about side effect on you myPIserver object.

                  I would recommend to always call connect, even if the connection is already opened, AF SDK will just ignore the connect call it the server is already connected and there is no performance cost there.

                   

                  What you are seeing is the debugger that is preventing the evaluation because that would lead to a function call and possibly modify your program behavior.  The debugger does not know what the program is doing, imagine you move the mouse over a function that writes data and returns some text, each time you put your mouse over the function while debugging you would write data... If you want to see what those variable contains, I'd recommend you add a watch expression instead and force the refresh. For more details, you should loook at this article from Microsoft: Side Effects and Expressions.

                   

                  Please let me know if this answers your question,

                  1 of 1 people found this helpful
                    • Re: Connect PI Data Archive via PI ACE code
                      Paurav Joshi

                      Excellent Patrice. It indeed answered our query.

                       

                      There is reason we didn't do explicitly connect call. We observed that after adding connect call explicitly to PI Data Archive, more time has been spent in  b/w ace code starts and fetching data.

                       

                      Cheers,

                      Paurav

                        • Re: Connect PI Data Archive via PI ACE code
                          pthivierge

                          Hello Paurav,

                           

                          I am glad this helped.

                           

                          Regarding the connection: it is considered an expensive operation to connect to a server. There are a lot of things going on ( Network calls, Authentication, etc.).

                          If you look at the documentation, Connecting to a PI Data Archive, here is what is stated:

                          There are several methods for connecting to a PI Data Archive. The AF SDK will handle caching objects and connections to the server, therefore you should only close a connection when you are through using the server for a long period of time. This is different from typical programming against a database where you open a connect, get the data, and then close the connection.

                          This means you should keep you server object at a higher level in your application so it lives for the entire duration of the execution of your PI ACE application. 

                          In your case, in VB.NET, you may create a global public MyServer variable in a Module and call the FindPIServer in the moduleDependantInitialization Method.  This should be only called once.

                          Then, in your ACECalculation method, you should call MyServer .Connect() Each time it is called..  The first time it will take a little more time.  But after the first connection, as the AF SDK will keep the connection in the cache, that will be very fast and the Connect() will be very fast.  If I remember well, the connection stays cached for about 5 minutes (configurable).