Just thought I would post about this quickly as its an error message that I ran into recently that took me quite a while to figure out. So to save other .NET developers spending ages trying to work out why it was happening like I did, I’ll explain how you can get rid of this rather annoying problem.
You try to use the DirectorySearcher to find some objects in AD but get the error “The directory service is unavailable” (error number 2147016689).
Cause and Solution
This is actually be caused by the structure of your search filter, and nothing to do with the directory service being unavailable. Whilst some LDAP query utilities will let you use a filter like this to specify an “AND” operation (ie only objects that match all parts of the filter will be returned):
It seems that the .NET DirectorySearcher does not like this and you need to explicitly add the ampersand character in there, like so:
and that simple action should stop you getting this error 🙂