Link to home
Start Free TrialLog in
Avatar of itedstrom
itedstrom

asked on

Updating the Active Directory manager field via C#

I am updating numerous fields in Active Directory, successfully, via C# and pulling data from a SQL database:

DirectoryEntry deAD = new DirectoryEntry("LDAP://AD1/CN=" + empCommonName + ",OU=EI Users,DC=ei,DC=mycompanyname,DC=com");
//output the data to the screen so that we can at least see the order of updates
Console.WriteLine("empCommonName value = " + empCommonName + " manager name = " + ManagerNm +  "ADCommonnamevalue =  " + deAD.Properties["CN"].Value);
if (empCommonName != deAD.Properties["CN"].Value)
    {if (PHextension != null && PHextension.Length>0){deAD.Properties["telephoneNumber"].Value = PHextension;}
   if (empDepartment != null && empDepartment.Length>0){deAD.Properties["department"].Value = empDepartment;}
   if (empTitle != null && empTitle.Length>0){deAD.Properties["title"].Value = empTitle;}
...etc.

I now need to update the manager field in AD, and I am trying this:

if (ManagerNm != null && ManagerNm.Length>0) {deAD.Properties["manager"].Value = "CN=" + ManagerNm + ",OU=myCompanyName,dc=DC,dc=com" ;}

I am understanding that I need to pass the inforamtion as above and am receiving the error below:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in system.directoryservices.dll
Additional information: A constraint violation occurred.

I know I'm passing the correct "manager" from my SQL database, though I may be struggling with a simple syntax issue.  Any help would be greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itedstrom
itedstrom

ASKER

Thanks Chris!!  That was my problem.  I was struggling with this for a while and didn't realize that I even needed the full
CN=" + ManagerNm + ",OU=myCompanyName,dc=DC,dc=com
to make this update in the first place.  Thanks!