I've been banging my head against the .Net 3.5 PrincipalContext, trying to establish a connection to OpenLDAP that is installed on the same machine as my Visual Studio 2010 IDE (machine name is dev001).
Here is my simple LDAP structure:
- base (dc=test,dc=com)
- testadmin (cn=testadmin,dc=test,dc=com)
- accounts (dc=accounts,dc=test,dc=com)
- testuser (cn=testuser,dc=accounts,dc=test,dc=com)
Here are the code snippets I've tried:
Snippet #1 : Combinations of name: "localhost", "localhost:389", "dev001", "dev001:389", "test", "test.com"
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, "localhost", "dc=accounts,dc=test,dc=com", "cn=testadmin,dc=test,dc=com", "testadminpassword");
Snippet #2 Combinations of name: "localhost", "localhost:389", "dev001", "dev001:389", "test", "test.com"
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, "localhost", "dc=accounts,dc=test,dc=com", "testadmin", "testadminpassword");
I have yet to establish a connection to the server.
When I use "localhost", "localhost:389", "dev001", "dev001:389", or "test", I get the error:
System.NullReferenceException: Object reference not set to an instance of an object.
When I use "test.com" I get the error:
System.DirectoryServices.AccountManagement.PrincipalServerDownException: The server could not be contacted. ---> System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable.