?
Solved

Updating the Active Directory manager field via C#

Posted on 2009-07-15
2
Medium Priority
?
961 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 200 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
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…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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