AnsweredAssumed Answered

PISDK with VBA - Error -2147024891

Question asked by henderson on Jul 25, 2016
Latest reply on Jul 28, 2016 by Charles Henze

I have a VBS file to get values from a TAG using PISDK.

 

I have many users running this files, but two of them are getting this error:

-2147024891 - Unable to open a session on a server.  The user name and password may be incorrect.  server.domain.com

 

I found this know issues

https://techsupport.osisoft.com/Troubleshooting/KB/KB01164

 

I think that this one may be my problem
20095OSI8 - Connections fail when the PISDK is impersonated as a network user

 

Can someone help me to implement this suggested solution?
"A second method (programmatic) is to create a PISDK object or ServerManager object and either write a message to the local log file or get the servers collection before impersonation, then impersonate and execute the desired code."

 

Here is my code

Function piVerified(tag, DATAi, fator, decPlaces, doTruncate, doRound)
    Dim myPISDK
    Dim srv
    Dim pt
    Dim pd
    Dim dtI
    Dim pv
    Dim nval
    Dim retorno
    If tag = "" Or DATAi = "" Then
        piVerified = 0
        Exit Function
    End If
    Set myPISDK = CreateObject("PISDK.PISDK")
    Set pv = CreateObject("PISDK.PIValue")
    Set dtI = CreateObject("PITimeServer.PITimeFormat")
    If myPISDK Is Nothing Then
        piVerified = "Erro"
        Exit Function
    End If
    Set srv = myPISDK.Servers.Item("servername")
    Set pt = srv.PIPoints(tag)
    Set pd = pt.DATA
    dtI.InputString = CStr(DATAi)
    Set pv = pd.ArcValue(dtI, 3, Nothing)
    If pv.IsGood Then
        retorno = CDbl(pv.Value)
        retorno = retorno * fator
        If doRound Then
            retorno = Round(retorno, decPlaces)
        End If
        If doTruncate Then
            retorno = truncate(retorno, decPlaces)
        End If
    Else
        retorno = "Erro"
    End If
    piVerified = retorno
End Function

Outcomes