Active Directory connection Failure
Clash Royale CLAN TAG#URR8PPP
Active Directory connection Failure
I need a small help. I am new to active directory. I want to connect my active directory with c#. Here is the sample code i have wrote.
public void GetConnection()
var username = "xxxx";
var domain = "xxxx";
var password = "xxxx";
var path = "LDAP://xxxx/CN=xx";
DirectoryEntry de = new DirectoryEntry(sDomain + "/" + sDefaultOU, sUsername, sServicePassword, AuthenticationTypes.ServerBind);
DirectorySearcher ds = new DirectorySearcher(de);
ds.Filter = "(&(objectClass=Users))";
var sr = ds.FindAll();
if (sr != null)
MessageBox.Show("success");
else
MessageBox.Show("error");
}
There is a COMException was unhandled
near
COMException was unhandled
var sr = ds.FindAll();
The error is:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.DirectoryServices.dll
Additional information: Unspecified error
Can I have some help in fixing the issue? Thanks in advance
Yes.to get all the a value from all the users such as Telephone number.
– user3200722
Aug 6 '14 at 3:03
What is the value that you construct for the constructor of the
DirectoryEntry
? What do you have in sDomain
and sDefaultOU
?– marc_s
Aug 6 '14 at 4:58
DirectoryEntry
sDomain
sDefaultOU
1 Answer
1
Step 1
static DirectoryEntry createDirectoryEntry()
// create and return new LDAP connection with desired settings
//This is for ssl secure port for non secure port just make 636 as 389 and //change Authentication as None
DirectoryEntry ldapConnection = new DirectoryEntry("LDAP://mysystem.domain.com:636","Admin","Domain123",AuthenticationTypes.SecureSocketsLayer);
return ldapConnection;
**
**
In the main function u need to write below function
DirectorySearcher _searcher = null;
SearchResult result_user = null;
DirectoryEntry de = createDirectoryEntry();
object o = de.SchemaEntry;
_searcher = new DirectorySearcher(de, "(&(objectClass=user)(SAMAccountName=" + "user1" + "))");
if (_searcher != null)
result_user = _searcher.FindOne();
de.Close();
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What are you trying to do? Get a list of users?
– Leo
Aug 6 '14 at 2:54