CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2008
    Posts
    3

    Constraint Violation Problem

    How can I check the manager property using the distinguishedName for updating?

    I am trying to update the manager property in Active Directory using data from a database. I need to check if the manager name from the db is the same as in Active Directory, if the name is not the same don't do nothing. If the name is the same update the name for the manager.

    I found this code over the Internet but I don't understand it. I what the guy refers to with dc1.ad.... + dnOfManager. I know what the domain is but not the rest. Any help will be very appreciated.

    Code:
    if(DirectoryEntry.Exists("LDAP://dc1.ad.domain.com/" + dnOfManager))
    {
    // update user object with dnOfManager
    }
    else
    {
    // manager object does not exist
    }
    
    This is what I am trying:
                    try {
                      string supervisor = "";
                      string lastName = "";
                      string firstName = "";
                      string mngr = "";
    
                      supervisor = oEmployee.Manager;
    
                      if (supervisor.Contains(",")) {
                        string[] split = supervisor.Split(new Char[] { ',' });
                        lastName = split[0];
                        firstName = split[1];
                        mngr = "CN=" + lastName + @"\," + firstName + ",CN=Users,DC=domain,DC=net";
                      }
                      if (DirectoryEntry.Exists("LDAP://" + "CN=" + lastName + @"\, " +
                          firstName + "," + "CN=users,DC=domain,DC=net")) {
                        if (supervisor != String.Empty) {
                          dentry.Properties["manager"].Value = mngr;
                        }
                      }
                      else {
                       
                        Console.WriteLine("Could not update Manager Property in Active Directory.");
                        if (flE.Exists) {
                          using (sw = flE.AppendText()) {
                            sw.WriteLine("===========================");
                            sw.WriteLine(DateTime.Now.ToShortDateString() +
                                   " " + DateTime.Now.ToShortTimeString());
                            sw.WriteLine("Could not update Manager for: " + oEmployee.EmpFullName + " : " + oEmployee.empId);
                            sw.WriteLine(" ");
                            sw.WriteLine("===========================");
                          }
                        }
                      }
                    } 
                    catch (Exception e) {
                      if (flE.Exists) {
                        using (sw = flE.AppendText()) {
                          sw.WriteLine("===========================");
                          sw.WriteLine(DateTime.Now.ToShortDateString() +
                                 " " + DateTime.Now.ToShortTimeString());
                          sw.WriteLine("Error: " + e.Message);
                          sw.WriteLine("Trying to update the Manager Property in Active Directory.");
                          sw.WriteLine("EmployeeID: " + oEmployee.empId);
                          sw.WriteLine(" ");
                          sw.WriteLine("===========================");
                        }
                      }
                    }
    Last edited by member_1222; November 18th, 2008 at 07:24 AM.

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Constraint Violation Problem

    Please use code tags, and edit your existing post so that it is readable....Thanks!
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Nov 2008
    Posts
    3

    Re: Constraint Violation Problem

    How do I add them?

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Constraint Violation Problem

    Quote Originally Posted by member_1222 View Post
    How do I add them?
    Did you read the FAQs (frequently asked questions) especially the one titled "BEFORE you post"???

    They are also codered in my signature (but it looks like you didnt set up your profile to enable private messaging - so issues like this do not clutter the thread, and probably did not enable the viewing of signatures.

    Also a search on "Code Tags" would have turned up samples...

    They are the like the following but without spaces inside the brackets

    [ code]
    paste your code here.
    [ /code]
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured