Error while trying to query Active Directory - Requires App Pool recycling

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

iis
active-directory
application-pool
asked on Stack Overflow Jul 26, 2018 by Grant

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0