7

I have the following chunk of code in a .NET web app used to query AD for a user

using (DirectoryEntry de = new DirectoryEntry(ldap))
{
    using (DirectorySearcher adSearch = new DirectorySearcher(de))
    {
        adSearch.Filter = "(&(objectCategory=person)(objectClass=user)(samAccountName=username))";
        SearchResult adSearchResult = adSearch.FindOne();
    }
}

When I run this, I sometimes get the following error:

System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000) 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.FindOne()

When this error is being thrown, it errors every time it runs. To correct this, I have to go to the IIS App Pool associated with this web app and recycle it. After recycling, the code works ... for a period of time. Then the error comes back a few hours later.

Additional information to note:

  • The App Pool is still running when it errors. Still, recycling fixes it
  • I have this same code running on 2 different web servers that are identically configured. This issue occurs on the first web server but never on the second
  • The App Pool is running under an AD service account. The same account is used on the app pool of both servers
  • I have tried recreating the App Pool associated with this web app without success

I would greatly appreciate any suggestions on where to look in IIS for a permanent solution. I can't be recycling the app pool every few hours.

Thanks

Grant
  • 81
  • 3
  • You might want to get a network trace when this happens and/or flip on ADSI tracing in Windows. I wonder if you are getting referred to a domain controller that is down or inaccessible. – Brian Desmond Jul 26 '18 at 21:28
  • @BrianDesmond, thanks, I'll take a look at that. The problem is, I never know when it's going to go down again. As for the DC, I'm not sure, but given that web server 2 continues to work, and they're both on the same subnet, I'd be skeptical. But will poke around and see what I can find. – Grant Jul 26 '18 at 22:34
  • I have this same issue. I tried turning on ADSI tracing which records events when I don't get the COM exception but when the error occurs the trace records nothing. – jon antoine Jan 15 '19 at 15:12
  • Ever get this figured out? – Bob May 03 '19 at 14:30
  • I answered a similar question here: https://stackoverflow.com/questions/36259818/intermittent-unknown-error-from-active-directory/57789441#57789441 – jon antoine Sep 04 '19 at 15:18

0 Answers0