Exception: The server is not operational while querying the AD

  • Thread starter Thread starter P.L.
  • Start date Start date
P

P.L.

Dear experts,

My program raised an exception - "The server is not operational" after
it keeps querying the AD server thousand times. The strange thing is
that the exception only happens after No. 3800 times query, sometimes
No. 3824th query, sometimes No. 3864th query, etc.

Stranger, when I run the program inside VS.NET 2005 in debug mode, the
program stops at the break point (inside catch (Exception e)); then I
press continue to run, the program will finish all 6000 queries with
only one exception. However, if I run this program directly in
Windows, the program will raise thousand exceptions (from 38xxth to
6000th), non-stop.

Any advice and suggestion would be highly appreciated.

Code:
private DirectoryEntry root = new DirectoryEntry("...");
root.AuthenticationType = AuthenticationTypes.Delegation;
root.Username = "...";
searcher = new DirectorySearcher(root);
searcher.PropertiesToLoad.Add("number1");
searcher.PropertiesToLoad.Add("field1");
searcher.PropertiesToLoad.Add("field2");
searcher.SizeLimit = 5000;
searcher.ClientTimeout = new TimeSpan(0, 5, 0);
searcher.ServerTimeLimit = new TimeSpan(0, 5, 0);

SearchResultCollection src = null;
SearchResult sr = null;
string number = "0000000000";
counter++;
DateTime methodstart = DateTime.Now;

try
{
searcher.Filter = "(&((addomain=" + account[0] + ")(adsamaccount="
+ account[1] + ")))";
sr = searcher.FindOne();
//src = searcher.FindAll();

//if (src.Count > 0)
// sr = src[0];

if (sr != null)
{
ResultPropertyValueCollection rpvc = sr.Properties["number1"];

if (rpvc.Count > 0)
number = rpvc[0].ToString();
}
}
catch (Exception e)
{
// log to the file
DateTime exceptiontime = DateTime.Now;
Console.WriteLine(counter.ToString() + ": program start: " +
starttime + " method start: " +
methodstart.ToString() + " exception time: " +
exceptiontime.ToString() +
", Exception - SearchLDAP(" + account[0] + "\\" + account[1]
+"): " +
e.Message + "\r\n");
}
finally
{
if (src != null)
src.Dispose();
}
return number;
}
 
Back
Top