Search code examples
c#active-directoryldap

Active Directory The user name or password is incorrect


I have a problem when using Active Directory.

It's weird that my program run fine on my computer but when I copy it to another PC, this error shows up.

I read a lot about AD's issues, but still don't have solution. Please help me to take a look. Thank you

string LDAPPath = "LDAP://xxxxxxx/xxxxxx"; // Sorry I can't show it here

DirectoryEntry entry = new DirectoryEntry(LDAPPath);

DirectorySearcher mySearcher = new DirectorySearcher(entry);

mySearcher.Filter = string.Format("(&(objectClass=group)(sAMAccountName=*))");
mySearcher.PageSize = 5000;

mySearcher.PropertiesToLoad.Add("member");
mySearcher.PropertiesToLoad.Add("name");

SearchResultCollection mysrs = mySearcher.FindAll();

Exception

enter image description here


Solution

  • This error says that there is a problem with the ldap connection.

    I have a couple of suggestions:

    1. add username and password to DirectoryEntry.
    DirectoryEntry("LDAP://xxxxxxx/xxxxxx", username, password);
    
    1. check the connection string. you can loook here for more refernce - https://serverfault.com/questions/130543/how-can-i-figure-out-my-ldap-connection-string