Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Updating the Active Directory manager field via C#

Posted on 2009-07-15
2
Medium Priority
?
981 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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

610 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