c# - Updating AD User information -
i having problem updating user information in active directory db...
when run following code error:
the specified directory service attribute or value not exist
the problem path using save information this:
cn=ad test,ou=container name,dc=us,dc=flg,dc=int
ad test
username in ad trying update.
and believe should be:
cn=ad test,ou=container name, ou=server name,dc=us,dc=flg,dc=int
i new directory services appreciate in finding out why cannot update... thank in advance
public bool updateactivedirectory(string ldapservername, string custid, employee sqlresult) { try { directoryentry rootentry = new directoryentry("ldap://" + ldapservername, "usrename", "password", authenticationtypes.secure); directorysearcher searcher = new directorysearcher(rootentry); searcher.filter = "(samaccountname=" + sqlresult.logonnt + ")"; searcher.propertiestoload.add("title"); searcher.propertiestoload.add("street"); searcher.propertiestoload.add("1"); searcher.propertiestoload.add("st"); searcher.propertiestoload.add("postalcode"); searcher.propertiestoload.add("department"); searcher.propertiestoload.add("mail"); searcher.propertiestoload.add("manager"); searcher.propertiestoload.add("telephonenumber"); searchresult result = searcher.findone(); if (result != null) { // create new object search result directoryentry entrytoupdate = result.getdirectoryentry(); entrytoupdate.properties["title"].value = sqlresult.title; entrytoupdate.properties["street"].value = sqlresult.address; entrytoupdate.properties["1"].value = sqlresult.city; entrytoupdate.properties["st"].value = sqlresult.state; entrytoupdate.properties["postalcode"].value = sqlresult.zipcode; entrytoupdate.properties["department"].value = sqlresult.department; entrytoupdate.properties["mail"].value = sqlresult.emailid; entrytoupdate.properties["manager"].value = sqlresult.managername; entrytoupdate.properties["telephonenumber"].value = sqlresult.phone; entrytoupdate.commitchanges(); console.writeline("user updated"); } else { console.writeline("user not found!"); } } catch (exception e) { console.writeline("exception caught:\n\n" + e.tostring()); } return true; }
maybe typo?
the third property you're trying update:
entrytoupdate.properties["1"].value = sqlresult.city;
is 1 (1
) in there? should small l (l
) instead.
also: manager's name must distinguished name of manager - whole
cn=manager,cn=ad test,ou=container name, ou=server name,dc=us,dc=flg,dc=int
thing - not name itself.
if doesn't - go old-school debugging technique:
- update single property; if fails --> that's problem case - figure out why it's problem.
- if works: uncomment second property , run again
-> repeat on , on again, until find culprit
Comments
Post a Comment