Connecting to a PIServer with a domain user

I'm trying to use the AF SDK to connect to a PI Server like this (simplified):

PIServers piServers = new PIServers();
_server = piServers[serverName];



string domain = mydomain;
string username = myusername;
string password = mypassword;


NetworkCredential netCred = new NetworkCredential(username, password, domain);


_server.Connect(netCred);

 

I've mapped the user to the piadmins Identity on the PI Server, but when I try to connect, I get an exception with the message "Cannot connect to the PI Data Archive."

 

In the PI Message Logs I get the following message: "Unsuccessful login  ID: 105. Address: 172.19.30.185. Name: God.Tag.Server.Console.vshost.exe(1748):remote. Credentials used: petter.brodin. Method: Explicit Login. Error: [-12001] Name Not Found in PInt"

 

Is there any reason why this shouldn't work? Is there a better way to approach this when attempting to log in with a domain user?

Parents Reply Children
  • Hi and thanks for the reply.

     

    First of all, apologies for decompiling the code. I got a bit overeager and forgot to check if it went against the Terms&Services. It won't happen again!

     

    Thanks for the explanation as well, it makes sense. Just to make sure: are you saying it should be possible to connect with credentials as a user on a different domain? We often deploy our software to client networks where we don't have full control of the network, so I can imagine (though based on what you say I hope we don't end up in) a situation where we'll be have to specify domain, username and password through a NetworkCredentials object.

  • I figured out why the proposed solution in the linked thread doesn't work for me: I'm using a PIServers object (a collection of PIServer objects) to connect to the PIServer directly, while the example code uses a PISystems object (a collection of PISystem object which "represents a single logical data store for the AF SDK").

     

    I tried copying the example code exactly, but replaced PISystems with PIServers, and it failed just as previously.

  • Hello Petter,

     

    As I already answered here Re: AFSDK: How to connect to a PI system across domains thru AFSDK C#?  the problem is probably elsewhere and not with the NetworkCredential object.

    I am also sorry to repeat here that disassembling, decompiling, or reverse engineering OSIsoft products is in violation of the PI Developers Club Agreement.  You agreed to not do that.

    As you have already found out, if you need to connect with the current user, there is no need to pass any credentials neither to force the connection.  The AF SDK will use the user who started the process by default.

    Also, forcing the connection is not necessarily a good idea since you are loosing the benefit of the AF Connection cache.  AFSDK will cache the connections so if the same user is connecting several time ( in the same process) the cached connection will be used and no time will be lost to perform the connection.

     

    Hope this helps,