Quick note to myself: An error message
The directory service is unavailable (English)
Der Verzeichnisdienst ist nicht verfügbar (German)
when querying an LDAP ApacheDS server can be caused by the wrong authentication type.
The full exception trace was:
System.Runtime.InteropServices.COMException occurred
ErrorCode=-2147016689
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindAll()
In my code, I did a call to
var de =
new DirectoryEntry(
@"LDAP://localhost:10389/ou=users,ou=someou,dc=domain,dc=com",
@"uid=admin, ou=system",
@"********",
AuthenticationTypes.Secure);
which failed. After I changed it to
var de =
new DirectoryEntry(
@"LDAP://localhost:10389/ou=users,ou=someou,dc=domain,dc=com",
@"uid=admin, ou=system",
@"********",
AuthenticationTypes.None);
everything worked as expected.