Solved

Updating the Active Directory manager field via C#

Posted on 2009-07-15
2
924 Views
Last Modified: 2012-05-07
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.
0
Comment
Question by:itedstrom
2 Comments
 
LVL 70

Accepted Solution

by:
Chris Dent earned 50 total points
ID: 24862592

I would double check the details you have for ManagerNm, because the most common cause of that particular error is when the path specified is incorrect.

Perhaps try creating a directory entry to verify the path you're using?

DirectoryEntry deManager = new DirectoryEntry("LDAP://AD1/CN=" + ManagerNm + ",OU=myCompanyName,dc=DC,dc=com");
Console.WriteLine(deManager.Name);

Chris
0
 

Author Closing Comment

by:itedstrom
ID: 31603889
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!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question