locked
Query LDAP for computer names doesn't work RRS feed

  • Question

  • User748184433 posted
    Hello guys I have the following code :

    public static List<string> GetComputers()
    {
    List<string> ComputerNames = new List<string>();

    DirectoryEntry entry = new DirectoryEntry("MyLDAP"); //I can t put my real LDAP online so I put MyLDAP
    //Debug.WriteLine(entry.count());
    DirectorySearcher mySearcher = new DirectorySearcher(entry);
    mySearcher.Filter = "(objectCategory=computer)";
    mySearcher.SizeLimit = int.MaxValue;
    mySearcher.PageSize = int.MaxValue;
    mySearcher.PropertiesToLoad.Add("name");
    SearchResultCollection resultCol = mySearcher.FindAll();
    SearchResult result;
    for (int counter = 0; counter < resultCol.Count; counter++)
    {
    result = resultCol[counter];
    string ComputerName = result.GetDirectoryEntry().Name;
    ComputerNames.Add(ComputerName);
    }

    //mySearcher.Dispose();
    //entry.Dispose();

    return ComputerNames;
    }
    And I have this error at this line :
    Error : SearchResultCollection resultCol = mySearcher.FindAll();
    COMException was unhandled by user code
    The servor is not operational

    Do you know where the problem comes from ? Is it about my LDAP that is wrong, or my filter ...
    I need to get all the computer name in a list.
    Thanks for your help :-)
    Thursday, February 18, 2016 2:12 PM

All replies

  • User-166373564 posted

    Hi,

    Error : SearchResultCollection resultCol = mySearcher.FindAll();
    COMException was unhandled by user code
    The servor is not operational

    Could you provide any more background about this issue? it will be helpful for us to troubleshoot.

    Regards,

    Angie

    Friday, February 26, 2016 9:38 AM