8 Replies Latest reply on Nov 4, 2016 12:21 PM by pthivierge

    PI DataLink 2015 connect via code


      Hi everyone,


      we are trying to update an old PI DataLink report to work with new DataLink 2015.


      The old VBA code used a specific PI user to connect Excel and DataLink through PI-SDK to a PI Server using the object PISDKDlg.Connections.

      With recent versions of DataLink, PI SDK objects do not work as the DataLink connection are done through AF-SDK and connecting the PI -SDK part won't help.


      I was thinking about using an intermediate AF Wrapper library to accomplish the connection operation for DataLink and I suppose it should work easily.

      Any other idea?

        • Re: PI DataLink 2015 connect via code

          Hello Nicola,


          Have you thought of using PI Web API? if it is available, and you can find all the calls you need, that would be a good solution on the long term.

          How to use PI Web API with VBA - Introduction


          Wrapping AF SDK calls into a COM exposed dll may work, but personally I find it difficult sometimes to work with especially for the deployment part.

          If this is really the path you want to go with you can:

          • Write a COM wrapper to expose AF SDK functions to excel --> see example here AF Wrapper For ProcessBook
          • Create a VSTO Excel AddIn that will integrate with excel
          • Create your AddIn with Excel-DNA.  I have used it successfully in the past as I found it easier to deploy (the .xll format is easy), to use. But beware you don't have intellisense on the Excel objects.  But this is really a question of preferences.


          Worth to mention, Visual Studio allows you to create a Click Once installation package.  This allows you to place the installer on a network drive, and after users install it from there, each time they start the application, it will trigger the update mechanism and see if there is a new version to install. That makes the deployment much easier.


          Hope this helps!

          1 of 1 people found this helpful
          • Re: PI DataLink 2015 connect via code

            Hello Nicola,


            Recent versions of PI DataLink, and I believe this includes PI DataLink 2015, are running in their own separate application domain. This is done for security reasons and means that you cannot piggy bag on the PI DataLink connection. Just in case this is what you have in mind. Besides that Patrice Thivierge has provided a complete list of available options.

            1 of 1 people found this helpful
              • Re: PI DataLink 2015 connect via code

                Hi Gregor,


                this was part of my doubt. I know DataLink connects through a different application domain, and I wanted to understand if it is possible getting that to connect using a specific user.


                I understand I cannot force DataLink to connect with a speciifc user by code. Am I right? Can you confirm it, please?

              • Re: PI DataLink 2015 connect via code

                Hello Nicolas,


                After reading more on the exchange on this post I think I have another solution.


                If understand well, you just need to have PI DataLink to connect the PI System ( AF and PI Data Archive) with a different user than the user that is logged on, correct?


                In this case you can use the Windows Credential Managers to override the current user and connect the server(s) with other credentials.

                This technique does not require any line of code, it only requires to configure User's windows profile so the credential manager contains the entries to connect to the appropriate server with the required username and password.

                More details about the Credential Manager here:

                KB01457 - Using Windows Credential Manager with PI applications

                How to Add Credentials to the Windows Credential Manager Vault


                I also had a chat with a college that told me you opened the case #745949 on this topic, I am mentioning it here for internal reference.


                Please let me know if this solution works for you.


                ps: you need to configure the same server name as you have configure in your PI AF SDK Connections.  e.g. myserver.osisoft.com or myserver