7 Replies Latest reply on Aug 30, 2011 6:14 AM by hanyong

    Errors while connecting to PI SDK server.

    sandeep.narang

      Hi Team

       

       

       

      I am using a WCF service in which I am connecting to PI SDK Server for PI eventing . This WCF service will be used by a windows application client. I am using the following piece of code to connect to the server.

       
      if (!new PISDK.PISDK().Servers[serverName].Connected)
                              {
                                  if (!string.IsNullOrEmpty(serverName))
                                  {
                                      server = new PISDK.PISDK().Servers[serverName];
                                  }
                                  else
                                  {
                                      throw new Exception("Please provide a valid server name.");
                                  }
                                  server.Open(@"Trusted_Connection=true");
                              }
      

       

       

      This WCF service is deployed on a windows service. When user attempts to call the method on the service to connect to PI SDK server, it throws following errors frequently.

       
       1. "Too soon to attempt reconnection."
      
      2. "Unable to open a session on a server. [-10758] Failed to create remote
      connection."
      
      3. "Connection to the server lost."
      
      To solve these isues, we need to restart the windows service. One thing I m sure that these issues occurs only when connecting to PI SDK server.
      
      Can you plesse provide some information what could be the possible causes for these errors?
      Thanks
      Sachin
        • Re: Errors while connecting to PI SDK server.
          sandeep.narang

          I was able to reproduce the error no. 2 when i gave the network node on which PI server was not installed. But other errors I still have no clue.

            • Re: Errors while connecting to PI SDK server.
              hanyong

              Hi Sachin,

               

              Here's the explanation of the 1st error message you are seeing:

               

              PI SDK Programming Reference

              The Server object keeps track of the time at which a disconnection occurs. If Open is attempted before the timeout interval elapses, reconnection is not attempted and pseRECONNECTTOOEARLY is returned. Currently, the timeout interval is 60 seconds. This prevents applications with reconnection logic from becoming unresponsive while the PI-SDK times out attempting to reconnect to the PI server. For details on automatic reconnection behavior see the topic "Reconnection" referenced in the See Also section of this page.

              ...

              pseRECONNECTTOOEARLY = Too soon to attempt reconnection. The PI server connection was broken and the retry timeout interval has not yet elapsed. This prevents excessive connection attempts to the server that may make the PI-SDK application unresponsive.


              You might want to set some logic to control the reconnection to the server when a disconnection is detected. You can find more information about managing the connection to PI Server in PI SDK Programming Reference, Section "Programming Concept -> Authentication -> Implicit Connection -> Autoconnection - Reconnection - Close" 

               

              As for 3rd error, it seems like it is just suggesting that the existing connection to the PI Server is lost. I think we will need more information to figure out that is causing the error.

               

              I guess the code is executed whenever a connection is required. Is the error capture when the server.Open() call is executed? or after? 

               

              A small comment on the logic in your code, wouldn't it make sense to first check for valid server name before testing if the server is connected, instead of the other way round? 

                • Re: Errors while connecting to PI SDK server.
                  hanyong

                  Hi Sachin,

                   

                  A quick follow up, were you able to resolve your connection error problem? 

                   

                   

                    • Re: Errors while connecting to PI SDK server.
                      sandeep.narang

                      Hi Han

                       

                      I gone through the links u provided(Thanks for it :). It was suggested in these links that we need to call server.close method before opening any other connection. Here the problem is that since I am using OnNewValue_EventHandler for event notification, wil it not get afftected if i close the connection?

                       

                      Do u have any other resolution for this?

                        • Re: Errors while connecting to PI SDK server.
                          hanyong

                          Hi Sachin,

                           

                          Actually given that EventPipes are used to get data updates from the PI Server, the mechanism of EventPipes will help you to attempt reconnection in the background and a server disconnection is detected. There is another section in the PI SDK Programming Reference, on Reconnection (you can search in the programming reference help file for Reconnection to find it) which talks about this behaviour for EventPipes

                           

                          PI SDK Programming Reference

                          EventPipes Force Reconnection

                          Applications which use PI-SDK EventPipe objects, (provided by a number of different collections to feed the application the latest available data from the server), get an added benefit with regard to reconnection.  An active EventPipe (one that has one or more sign ups) will communicate with the server in the background, attempting to retrieve the desired data.  This communication follows the same rules as explicit calls described above.  When the application becomes disconnected, the EventPipe background processing will attempt to retrieve data at its configured PollInterval (usually 60 seconds or less depending on the EventPipe type) and will force reconnection.  Given this, an application that just grabbed an EventPipe for a PIPoint would reconnect automatically when it lost a server connection. Coupled with the background reconnection described above, the application reconnects automatically and never blocks execution.  Note, the EventPipe retrieves data on its own background thread so the limited blocking during disconnection detection does not occur on the application's main thread (unless the main thread is also making other server calls) leaving it free to process user input.

                           

                          One question I do have about your WCF service. What is the program flow like? Like what happens when an application is trying to get the data updates from the WCF service? When do you have to check establish a connection to PI Server like what you are doing in the code snippet?

                            • Re: Errors while connecting to PI SDK server.
                              sandeep.narang

                              Hi Han

                               

                              I have already provided the code snippet to connect to the server above. Actually this WCF service can accept multiple requests from the user. SUppose if a user is connected to a server A at the first time, second time it will check if server A is already connected then do not create a new connection( You can see in the snippet).

                               

                              My confusion is that this error is not reproducible for me means i dont know when the error would occur. Can you please let me know how can i reproduce this error.

                               

                              And i was seeing in this reference that i do not need to do anything to reconnect. If this will solve my issue if i implement the code as above snippet?

                                • Re: Errors while connecting to PI SDK server.
                                  hanyong

                                  Hi Sachin,

                                   

                                  Since the errors reported are connection errors. I think the easiest way to have an environment where the error is reproducible is a test environment where you can control if the PI Server is reachable from the WCF service. That way you can test your WCF service's operation when it comes to situation like PI Server is unreachable, PI Server was connected but connection broke, etc.

                                   

                                  The reference says that with EventPipe registered to a server, it will automatically attempt to reconnect when connection to PI Server is broken. But I think just with this mechanism will not solve your problem. Because connection error can still happen even with EventPipe trying to reconnect to the server in the background.

                                   

                                  You should probably look at how to handle situations when there is a connection error to the PI Server. Should you be returning an error to the user saying that there is an error processing the request? or you want to implement a mechanism to re-attempt to process the request after 1 minute?