Answered by:
DirectoryServicesCOMException

Question
-
User-1152693950 posted
Hello all, I have a web app that looks up a users email in AD and returns the email so the app can send a confirmation email. The lookup has been working fine for two weeks, but recently has started throwing an exception.
System.DirectoryServices.DirectoryServicesCOMException
[System.DirectoryServices.DirectoryServicesCOMException] Inner Exception at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_AdsObject() at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) at System.DirectoryServices.DirectorySearcher.FindOne() at JobDB.pullestimatenum.JobInsertedSql(Object sender, SqlDataSourceStatusEventArgs e) in C:\JobDB\JobDB\pullestimatenum.aspx.cs:line 106 at System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) at System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) at System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) at System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
This is the code I am using to get the email:
//Send user email DirectorySearcher searcher = new DirectorySearcher(); searcher.Filter = string.Format("sAMAccountName={0}", User.Identity.Name.Substring(Request.LogonUserIdentity.Name.LastIndexOf(@"\") + 1)); SearchResult user = searcher.FindOne(); string emailAddr = user.Properties["mail"][0].ToString() ?? "";
Does anyone see anything wrong with this code? I cannot figure out why this would have started all of a sudden?
Edit: I tried restarting the website, recycling the application pool, and republishing the website and it is still not working. It is fine when I debug it from my dev machine.
Thanks,
BrennanMonday, August 20, 2012 1:34 PM
Answers
-
User-1152693950 posted
I ended up redoing how I was contacting Active Directory, and it is now working.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 17, 2013 8:57 AM
All replies
-
User1515728814 posted
Hi,
I think the problem is that the server was looking at the wrong AD controller. It had to be written out COMPLETELY.
Monday, September 10, 2012 2:40 AM -
User-972150373 posted
I have the same error and I checked the names of the DC. The scenario is that I searched the groups (pimarios and nested) of a user and domain users to work perfectly but the other goes down when you run the statement: ds.FindAll (). This is the code
public SecurityGroups (string sAMAccountName, DirectoryEntry SearchRoot) { if (null == SearchRoot) throw new ArgumentNullException ("SearchRoot");
_searchRoot = SearchRoot;
FindOne (String.Format ("(& (objectCategory = person) (sAMAccountName = {0}))" sAMAccountName)); }
private void FindOne (string ldapFilter) { DirectorySearcher ds = new DirectorySearcher (_searchRoot, ldapFilter);
using (SearchResultCollection src = ds.FindAll ()) { if (src.Count> 0) _userResult = src [0]; }
if (null == _userResult) throw new ArgumentException ("User not found"); }
Both groups are by trusting relationship. and I see the simple (not groups nidados) utizando other code falls.
There are groups in both domains and do not know if that will be affecting.
Monday, October 1, 2012 5:21 PM -
User-1152693950 posted
I ended up redoing how I was contacting Active Directory, and it is now working.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 17, 2013 8:57 AM