Active Directory的COM异常 - 一个操作发生错误(0x80072020)发生错误、异常、操作、Directory

2023-09-02 11:47:36 作者:封刀战魔

我收到一个间歇性COM异常发生后的的操作错误(0x80072020)(如下图所示),当我尝试和查询Active Directory的使用方法 GroupPrincipal.FindByIdentity

下面是我的code:

  PrincipalContext CTX =新PrincipalContext(ContextType.Domain,Environment.UserDomainName);
GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(CTX,IdentityType.Name,组中找到);
 

我收到异常:

 内部异常信息:System.Runtime.InteropServices.COMException(0x80072020):出现操作错误。
  在System.DirectoryServices.DirectoryEntry.Bind(布尔throwIfFail)
  在System.DirectoryServices.DirectoryEntry.Bind()
  在System.DirectoryServices.DirectoryEntry.get_AdsObject()
  在System.DirectoryServices.PropertyValueCollection.PopulateList()
  在System.DirectoryServices.PropertyValueCollection..ctor(的DirectoryEntry条目,串propertyName的)
  在System.DirectoryServices.PropertyCollection.get_Item(字符串propertyName的)
  在System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
  在System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
  在System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
  在System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
  在System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext背景下,类型principalType,Nullable`1 identityType,串identityValue,日期时间refDate)
  在System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext背景下,类型principalType,IdentityType identityType,串identityValue)
  在System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext背景下,IdentityType identityType,串identityValue)
 
如何安装配置Active Directory

在code从 Windows服务 的Windows 2003 SP2的服务器上

运行

我还发现了另外一个堆栈溢出的问题,Active目录,列举了用户的gropus,COM异常,这表明启用Kerberos 作为在PrincipalContext构造一个选项,将解决这个问题,但我收到的不同的十六进制code 的比这个问题。

我的问题是

这是特定的COM异常肯定是一个身份验证问题?我需要确保释放软件在此之前将100%解决问题。 在有资源的地方,其中列出了所有可能的COM异常(十六进制)codeS,这样我可以帮助自己在未来会好一点? 解决方案

我现在已经发现了另一个答案Unable要在动态CRM CrmService API,其中指出,0x80072020的确是一个权限问题添加用户。我已经改变了我的服务,在域级别的帐户,而不是本地系统帐户运行,这似乎已经治好了我的问题。

I am getting an intermittent COM Exception "An operations error occurred (0x80072020)" (shown below) when I try and query Active Directory using the method GroupPrincipal.FindByIdentity

Here is my code:

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, Environment.UserDomainName);
GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "Group to find");

I am receiving Exception:

Inner Exception: System.Runtime.InteropServices.COMException (0x80072020): An operations error occurred.
  at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
  at System.DirectoryServices.DirectoryEntry.Bind()
  at System.DirectoryServices.DirectoryEntry.get_AdsObject()
  at System.DirectoryServices.PropertyValueCollection.PopulateList()
  at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
  at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
  at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
  at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
  at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
  at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
  at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate)
  at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue)
  at System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue)

The code is running from a Windows service on a Windows 2003 SP2 server.

I have found another Stack Overflow question, Active Directory, enumerating user's gropus, COM exception, suggesting that enabling Kerberos as an option in the PrincipalContext constructor will fix this problem but I am receiving a different hex code than in this question.

My questions are:

Is this particular COM Exception definitely an authentication issue? I need to be sure that this will 100% fix the problem before releasing the software. Is there a resource somewhere which lists all the possible COM exception hex codes so that I can help myself a bit better in the future?

解决方案

I've now found another answer Unable to add user with CrmService API in Dynamics CRM which states that 0x80072020 is indeed a permission issue. I have changed my service to run under a domain level account instead of the local system account and this seems to have cured my problem.