Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I've been at this for a while and I'm always getting:

System.DirectoryServices.AccountManagement.PrincipalServerDownException

Which I think means my connection setup(connection string) is wrong.

When I write "dsquery server" on cmd on the computer where the Active Directory is I get:

"CN=DCESTAGIO,CN=SERVERS,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=estagioit,DC=local"

I've tried the following connecting in the following ways:

1:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "192.168.56.101", "DC=estagioit,DC=local");


2:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "192.168.56.101/DC=estagioit,DC=local");


3:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "192.168.56.101/CN=DCESTAGIO,DC=estagioit,DC=local");


4:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "192.168.56.101/CN=DCESTAGIO,CN=SERVERS,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=estagioit,DC=local");


5:

PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "LDAP://192.168.56.101/CN=Users,DC=estagioit,DC=local");


And some other ways...

Any ideas on what's wrong and how I can make this connection work?

PS: The ip is correct seen as I've used it to ping and it's working.

PSS: I really, really need this working ASAP if you have any suggestions at all they're all welcome.
Posted
Updated 13-Apr-15 4:55am
v2
Comments
Richard Deeming 13-Apr-15 11:46am    
Is the computer where this code is running part of the domain? If so, try the constructor with the name and container parameters:
var thisPrincipalContext = new PrincipalContext(ContextType.Domain);

1 solution

The problem is how the "Principal Context" is written... it should be:
PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "DCESTAGIO");

in this case.

If you look at the documentation for the
PrincipalContext
constructors, it should be quite clear:
public PrincipalContext(ContextType contextType, string name)

or
public PrincipalContext(ContextType contextType, string name, string container)

So you basically need:

- your context type (here:
ContextType.Domain
)
- the domain name (try just the "Netbios" name, e.g. "YOURDOMAIN" - or leave NULL for "default" domain)
- optionally a container (as an LDAP path - a "distinguished" name, full path but without any LDAP:// prefix)
as seen in this answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900