3

Possible Duplicate:
How to know if my DirectoryEntry is really connected to my LDAP directory?

I am calling DirectoryEntry() with an invalid Domain on purpose to test how my C# application handles the case if a server goes down, etc. DirectoryEntry() does not throw an exception - it returns (seemingly normally) but when debugging, I cannot view the contents of directoryEntry - it times out on the variable expansion.

Its not until I perform an operation on the DirectorySearcher object that the program hangs for minutes before returning an exception "Server Is Not Operational". It appears setting the clientTimeout doesn't help either. Any suggestions?

TimeSpan timeout = new TimeSpan(0, 0, 0, 15, 0);
string domain = "asdf";
DirectoryEntry myDirectoryEntry = new DirectoryEntry("LDAP://" + domain);
DirectorySearcher mySearcher = new DirectorySearcher(myDirectoryEntry);
mySearcher.ClientTimeout = timeout;
mySearcher.Filter = "(&(objectCategory=person)(objectClass=user));
searcher.FindAll();  //this takes minutes with invalid domain!!!
Community
  • 1
  • 1
larz
  • 31
  • 1
  • I'm not sure, but I'm guessing that the `Guid` property will return an empty `Guid` on an invalid domain. – Mike Perrenoud Oct 19 '12 at 17:17
  • MessageBox.Show(entry.Guid.ToString()) - causes the same multiple minute hang - then throws an exception saying the "Server is not operational." – larz Oct 19 '12 at 17:43
  • 1
    So is it a viable solution for you to put a line of code in a `try-catch` that tries to access the `Guid` and if that specific exception type is caught then you know what happened? – Mike Perrenoud Oct 19 '12 at 17:52
  • 1
    Similar to: http://stackoverflow.com/questions/1063642/how-to-know-if-my-directoryentry-is-really-connected-to-my-ldap-directory – Brandon Oct 19 '12 at 18:33
  • @Brandon, yes that is a good verification, thanks! – Mike Perrenoud Oct 19 '12 at 18:41
  • All suggestions here still create the very long delay before the exception occurs. The very long delay is the issue i'm dealing with, not the exception. It seems setting the ClientTimeout has no effect - its on the order of 3 minutes or so that it takes before the exception occurs. – larz Oct 19 '12 at 19:02

0 Answers0