I am writing a .NET application to query an LDAP server, and I can't figure out how to look at exceptions and figure out what happened on the LDAP end. I'm using DirectoryServices, and trying to avoid anything that's specific to ActiveDirectory.
I create a DirectorySearcher, then do
try
开发者_StackOverflow{
SearchResult result = searcher.FindOne();
}
catch(Exception e)
{
// now what?
}
I expect certain types of errors to occur on the LDAP end, like user not found, account disabled, etc., and I'd like to identify these particular errors. Are there specific expection types?
I notice the innerException has a _COMPlusExceptionCode. Is this a reliable indicator of what went wrong on the LDAP side? I haven't been able to find an enumeration of these exception codes.
Any suggestions?
There's a list of all the ADSI error codes here which contains generic COM and generic ADSI errors, as well as the specific LDAP error codes for ADSI 2.0.
LDAP errors are notoriously hard to deal with - more often than not, you just get a "server unable to perform" or something like that, without much explanation what causes the server to be unable to do its job.
Now call .ToString()
and look at the human-readable text.
精彩评论