I was trying to pull data from a Microsoft Active Directory Group, and while attempting to query the data the aforementioned exception was occurring. An eagle eye debugging showed the cause and it was simple but stupid.
Following is the correct format of LDAP connection string
LDAP://abc.xyz.pqr.lab:389/CN=TheGroup,
CN=Users,DC=abc,DC=xyz,DC=pqr,DC=lab
But our dear programmer had done it a little differently, I think it was just a type, the wrong format of LDAP connection string was following
LDAP://abc.xyz.pqr.lab/CN=TheGroup,
CN=Users,DC=abc,DC=xyz,DC=pqr,DC=lab:389
This was causing the system to show the Active Directory related exception in C# .Net on Visual Studio 2008.
Notice the wrong positioning of LDAP port number, people some times make absolutely silly mistakes.
Keep in mind that 389 is default port for insecure communication with LDAP directory server. For secure exchange of data use LDAPS, default port for LDAPS is 636.
These port numbers are recommended, and LDAP servers use these out of the box. But not all LDAP servers always use port 389 and 636. It is possible to change the default LDAP port numbers, please check your directory server software's documentation for details.