DirectoryEntry Search Errors

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

Please excuse the double post if your reader shows this
as a new and as a reply. I can only use the web interface
and it puts my reply 34 pages in.

I am getting an error while trying to do a LDAP lookup
using the DirectoryEntry Object. What is caught is:

System.Runtime.InteropServices.COMException (0x80004005):
Error HRESULT has been returned from a call to a COM
component.

The error without the try..catch is

System.Runtime.InteropServices.COMException: Unknown
error (0x80005000)

related to my

// Do the search
foreach(SearchResult result in DirSearcher.FindAll())

code.

When I explicitly specify the DirectoryEntry parameters
it works fine, when I try to use a variable (LDAPQuery)
it fails. The string is being created properly as I can
assign it to a label and have it output correctly.

Any clues?


Code:

LDAPQuery = string.Format("\"LDAP://{0}\", \"{1}\", \"{2}
\"", domain, UsrName, UsrPass);

// This does not work
DirectoryEntry SearchRoot = new DirectoryEntry(LDAPQuery);

// This works
// DirectoryEntry SearchRoot = new DirectoryEntry
("LDAP://testdomain", "fubarjones", "Testing@9");

Jay
 
DirectoryEntry takes 3 arguments, not a single string!

Change your code like this:

string LDAPQuery = string.Format("LDAP://{0}", domain);
DirectoryEntry SearchRoot = new DirectoryEntry(LDAPQuery, UsrName, UsrPass);

Willy.
 
Thanks, that fixed it.

Jay
-----Original Message-----
DirectoryEntry takes 3 arguments, not a single string!

Change your code like this:

string LDAPQuery = string.Format("LDAP://{0}", domain);
DirectoryEntry SearchRoot = new DirectoryEntry (LDAPQuery, UsrName, UsrPass);

Willy.




.
 
Back
Top