【问题标题】:Cannot read all users from Active Directory - [DirectoryServicesCOMException] MoveNext()无法从 Active Directory 读取所有用户 - [DirectoryServicesCOMException] MoveNext()
【发布时间】:2020-06-05 10:02:43
【问题描述】:

我的团队正在使用一个用 C# 编写的程序来读取来自特定 OU 的所有用户。该程序的行为非常奇怪。有时它工作了几个星期,然后我们的 AD 或任何其他相关组件没有任何大的变化,它就会引发异常。然后它有几个星期不工作,一段时间后又开始正常运行。

代码

    DirectoryEntry searchRoot = new DirectoryEntry("<LDAP string>")

    searchRoot.AuthenticationType = AuthenticationTypes.None;
    DirectorySearcher search = new DirectorySearcher(searchRoot);

    search.Filter = <our filter>;
    search.PropertiesToLoad.Add("<some property>");
    search.PageSize = 1;

    SearchResult result;
    SearchResultCollection resultCol = null;

    try
    {
      resultCol = search.FindAll();
    }
    catch (Exception ex)
    {
      Console.WriteLine(ex.ToString());
    }

    if (resultCol != null)
    {
      Console.WriteLine("Result Count: " + resultCol.Count); //.Count throws the Exception
    }

例外

    Unhandled Exception: System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.

      at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()
      at System.DirectoryServices.SearchResultCollection.get_InnerList()
      at System.DirectoryServices.SearchResultCollection.get_Count()

Data: System.Collections.ListDictionaryInternal
Error Code: -2147016672
Extended Error: 8431
Extended Error Message: 000020EF: SvcErr: DSID-020A07A7, problem 5012 (DIR_ERROR), data -1018
HResult: -2147016672
Message: An operations error occured.
Source: System.DirectoryServices
Stack Trace: at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()
Target Site: Boolean MoveNext()

其他信息

  • 目标框架:.Net Framework 4.6.1(无其他库)
  • 程序在域控制器上执行

我的尝试

  • 我创建了一个循环来使用 枚举器并发现它将结果加载到特定的 元素然后崩溃
  • 总是相同的元素
  • 在第一次异常之后,所有重试也都失败了
  • 启动它的用户是域管理员(但我 也用企业管理员账户试过,所以是 可能不是权限问题)
  • 我已删除发生异常时应读取的用户,但在下一次运行时为前一个用户引发了异常

我已经到了一个点,我对解决这个问题没有更多的想法。感谢您的支持。

【问题讨论】:

  • 请分享更多调试细节,例如强制异常的特定元素的特征、元素的数量以及所涉及的软件和库的版本。
  • 你对这个特定元素的特征意味着什么?它是 System.DirectoryServices 命名空间中的 SearchResultCollection。您是在询问我加载的属性吗?
  • 我不精通 Active Directory,但一般来说,如果某些东西 “加载 [..] 到特定元素然后崩溃” 有关该特定元素的更多详细信息可以协助其他用户尝试帮助您回答问题。
  • 如果我删除了无法加载的用户,下次运行后将无法读取前一个用户。虽然,它可以在第一次运行时读取。
  • 不幸的是,基于ExtendedErrorMessage,我找不到任何有用的信息。我将使用异常的所有扩展信息更新问题。

标签: c# .net active-directory directoryservices directorysearcher


【解决方案1】:

这个答案只是总结了我们在 cmets 中的对话。

This thread 部分匹配您收到的错误:

problem 5012 (DIR_ERROR) data -1018

Microsoft MVP 的回答是:

这是数据库中的校验和错误,您的数据库中有损坏 数据库,这通常是由于磁盘或磁盘子系统故障或 可能是系统崩溃和数据未从写入缓存写入。

所以听起来你可能有同样的事情发生。

但可能只有一个 DC 有问题。因此,为了帮助您缩小范围,您可以在 LDAP 路径中指定 DC,如下所示:

LDAP://dc1.example.com/OU=Target,OU=My User Group,OU=My Users,DC=example,DC=com

这可以从两个方面帮助您:

  1. 它可以识别坏 DC,以便您知道需要修复哪个 DC(并可能在修复之前将其离线),并且
  2. 您可以专门针对一个好的 DC,以便您的脚本继续工作。

【讨论】:

    猜你喜欢
    • 2023-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多