Solved

Updating the Active Directory manager field via C#

Posted on 2009-07-15
2
892 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

Join & Write a Comment

Do you have users whose passwords are expiring and they are constantly calling you?  Well I sure did and needed a way to put an end to this.  We have a lot of remote users which would not be notified that their passwords were expiring since they wer…
Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
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 configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now