Connecting Tech Pros Worldwide Help | Site Map

Trying to get a name from Active Directory with DirectoryServices

  #1  
Old February 26th, 2007, 11:05 PM
jmDesktop
Guest
 
Posts: n/a
Can someone tell me why I get this error?

System.DirectoryServices.DirectoryServicesCOMExcep tion was unhandled
Message="An operations error occurred.\r\n"
Source="System.DirectoryServices"
ErrorCode=-2147016672
ExtendedError=8406
ExtendedErrorMessage="000020D6: SvcErr: DSID-03100684, problem 5012
(DIR_ERROR), data 0\n"


From:

private void Form1_Load(object sender, EventArgs e)
{
DirectoryEntry group = new DirectoryEntry("LDAP://CN=MyDomain"); //
represents your group you wish to look at

using (group)
{
DirectorySearcher ds = new DirectorySearcher(
group,
"(&(objectClass=user)(objectCategory=person))" , //only
retrieve user objects
new string[]{"sAMAccountName"}
);

//the part the you really need to do is next two lines
ds.SearchScope = SearchScope.Base;
ds.AttributeScopeQuery = "member";

using (SearchResultCollection src = ds.FindAll())
{
foreach (SearchResult sr in src)
sr.Properties["sAMAccountName"][0].ToString();
}
}

}
}

  #2  
Old February 27th, 2007, 07:55 AM
Peter Bradley
Guest
 
Posts: n/a

re: Trying to get a name from Active Directory with DirectoryServices


On what line does the error occur?

Peter

"jmDesktop" <needin4mation@gmail.comwrote in message
news:1172530250.471627.19060@p10g2000cwp.googlegro ups.com...
Quote:
Can someone tell me why I get this error?
>
System.DirectoryServices.DirectoryServicesCOMExcep tion was unhandled
Message="An operations error occurred.\r\n"
Source="System.DirectoryServices"
ErrorCode=-2147016672
ExtendedError=8406
ExtendedErrorMessage="000020D6: SvcErr: DSID-03100684, problem 5012
(DIR_ERROR), data 0\n"
>
>
From:
>
private void Form1_Load(object sender, EventArgs e)
{
DirectoryEntry group = new DirectoryEntry("LDAP://CN=MyDomain"); //
represents your group you wish to look at
>
using (group)
{
DirectorySearcher ds = new DirectorySearcher(
group,
"(&(objectClass=user)(objectCategory=person))" , //only
retrieve user objects
new string[]{"sAMAccountName"}
);
>
//the part the you really need to do is next two lines
ds.SearchScope = SearchScope.Base;
ds.AttributeScopeQuery = "member";
>
using (SearchResultCollection src = ds.FindAll())
{
foreach (SearchResult sr in src)
sr.Properties["sAMAccountName"][0].ToString();
}
}
>
}
}
>

  #3  
Old February 27th, 2007, 09:15 AM
Willy Denoyette [MVP]
Guest
 
Posts: n/a

re: Trying to get a name from Active Directory with DirectoryServices


"jmDesktop" <needin4mation@gmail.comwrote in message
news:1172530250.471627.19060@p10g2000cwp.googlegro ups.com...
Quote:
Can someone tell me why I get this error?
>
System.DirectoryServices.DirectoryServicesCOMExcep tion was unhandled
Message="An operations error occurred.\r\n"
Source="System.DirectoryServices"
ErrorCode=-2147016672
ExtendedError=8406
ExtendedErrorMessage="000020D6: SvcErr: DSID-03100684, problem 5012
(DIR_ERROR), data 0\n"
>
>
From:
>
private void Form1_Load(object sender, EventArgs e)
{
DirectoryEntry group = new DirectoryEntry("LDAP://CN=MyDomain"); //
represents your group you wish to look at
>
using (group)
{
DirectorySearcher ds = new DirectorySearcher(
group,
"(&(objectClass=user)(objectCategory=person))" , //only
retrieve user objects
new string[]{"sAMAccountName"}
);
>
//the part the you really need to do is next two lines
ds.SearchScope = SearchScope.Base;
ds.AttributeScopeQuery = "member";
>
using (SearchResultCollection src = ds.FindAll())
{
foreach (SearchResult sr in src)
sr.Properties["sAMAccountName"][0].ToString();
}
}
>
}
}


That's because the current user running this code is not a domain user, and as such has no
access permissions to the AD.
To solve this issue, either run this code as a domain user or specify explicitly credentials
in your DirectoryEntry constructor.

Willy.

  #4  
Old February 27th, 2007, 05:45 PM
jmDesktop
Guest
 
Posts: n/a

re: Trying to get a name from Active Directory with DirectoryServices


On Feb 27, 4:01 am, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
Quote:
"jmDesktop" <needin4mat...@gmail.comwrote in message
>
news:1172530250.471627.19060@p10g2000cwp.googlegro ups.com...
>
>
>
>
>
Quote:
Can someone tell me why I get this error?
>
Quote:
System.DirectoryServices.DirectoryServicesCOMExcep tion was unhandled
Message="An operations error occurred.\r\n"
Source="System.DirectoryServices"
ErrorCode=-2147016672
ExtendedError=8406
ExtendedErrorMessage="000020D6: SvcErr: DSID-03100684, problem 5012
(DIR_ERROR), data 0\n"
>
Quote:
From:
>
Quote:
private void Form1_Load(object sender, EventArgs e)
{
DirectoryEntry group = new DirectoryEntry("LDAP://CN=MyDomain"); //
represents your group you wish to look at
>
Quote:
using (group)
{
DirectorySearcher ds = new DirectorySearcher(
group,
"(&(objectClass=user)(objectCategory=person))" , //only
retrieve user objects
new string[]{"sAMAccountName"}
);
>
Quote:
//the part the you really need to do is next two lines
ds.SearchScope = SearchScope.Base;
ds.AttributeScopeQuery = "member";
>
Quote:
using (SearchResultCollection src = ds.FindAll())
{
foreach (SearchResult sr in src)
sr.Properties["sAMAccountName"][0].ToString();
}
}
>
Quote:
}
}
>
That's because the current user running this code is not a domain user, and as such has no
access permissions to the AD.
To solve this issue, either run this code as a domain user or specify explicitly credentials
in your DirectoryEntry constructor.
>
Willy.- Hide quoted text -
>
- Show quoted text -
I am the domain admin, does it try and run it under another process?

  #5  
Old February 27th, 2007, 08:15 PM
Willy Denoyette [MVP]
Guest
 
Posts: n/a

re: Trying to get a name from Active Directory with DirectoryServices


"jmDesktop" <needin4mation@gmail.comwrote in message
news:1172597652.314845.103030@a75g2000cwd.googlegr oups.com...
Quote:
On Feb 27, 4:01 am, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
Quote:
>"jmDesktop" <needin4mat...@gmail.comwrote in message
>>
>news:1172530250.471627.19060@p10g2000cwp.googlegr oups.com...
>>
>>
>>
>>
>>
Quote:
Can someone tell me why I get this error?
>>
Quote:
System.DirectoryServices.DirectoryServicesCOMExcep tion was unhandled
Message="An operations error occurred.\r\n"
Source="System.DirectoryServices"
ErrorCode=-2147016672
ExtendedError=8406
ExtendedErrorMessage="000020D6: SvcErr: DSID-03100684, problem 5012
(DIR_ERROR), data 0\n"
>>
Quote:
From:
>>
Quote:
private void Form1_Load(object sender, EventArgs e)
{
DirectoryEntry group = new DirectoryEntry("LDAP://CN=MyDomain"); //
represents your group you wish to look at
>>
Quote:
using (group)
{
DirectorySearcher ds = new DirectorySearcher(
group,
"(&(objectClass=user)(objectCategory=person))" , //only
retrieve user objects
new string[]{"sAMAccountName"}
);
>>
Quote:
//the part the you really need to do is next two lines
ds.SearchScope = SearchScope.Base;
ds.AttributeScopeQuery = "member";
>>
Quote:
using (SearchResultCollection src = ds.FindAll())
{
foreach (SearchResult sr in src)
sr.Properties["sAMAccountName"][0].ToString();
}
}
>>
Quote:
}
}
>>
>That's because the current user running this code is not a domain user, and as such has
>no
>access permissions to the AD.
>To solve this issue, either run this code as a domain user or specify explicitly
>credentials
>in your DirectoryEntry constructor.
>>
>Willy.- Hide quoted text -
>>
>- Show quoted text -
>
I am the domain admin, does it try and run it under another process?
>

Must be something wrong with the LDAP path then, if this: new
DirectoryEntry("LDAP://CN=MyDomain"); //
is your ldap path, then it is wrong.
The DirectoryEntry constructor should look something like this:

DirectoryEntry("LDAP://xxxx/cn=..., cn=.., dc=..., dc=...");
where xxx is or the domain name or the DC name or RootDSE or GC.
Please search MSDN "Binding to Active Directory Domain Services", for details about when and
where you should use one of them.

Willy.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gettting Logon Info from Active Directory in ASP.net hshah answers 0 April 12th, 2007 10:23 PM
Populating a DDL with users from Active Directory Jim in Arizona answers 2 August 1st, 2006 09:55 PM
get user details from Active Directory Dan Nash answers 4 November 18th, 2005 08:20 PM
losing connection to Active Directory huzz answers 10 August 3rd, 2005 09:25 AM