Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Unable to Update LDAP property "department"

Unable to Update LDAP property "department"

Scheduled Pinned Locked Moved Visual Basic
csharpwinformscomsysadminwindows-admin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David Mujica
    wrote on last edited by
    #1

    I'm trying to create a utility to perform a mass update of our Active Directory and all I get is the error, "Server is unwilling to process request." Below is my code:

    Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")

        Dim ds As New DirectorySearcher(de)
        ds.PropertiesToLoad.Add("department")
        ds.SearchScope = SearchScope.Subtree
    
        Dim ue As New DirectoryEntry   
        
        ds.Filter = String.Format("(SAMAccountName={0})", Me.tboxUserName.Text)
    
        Try
            ue = ds.FindOne.GetDirectoryEntry
    
            For Each sproperty As String In ue.Properties.PropertyNames
                debug.print(String.Format("{0}{1} : {2} ", System.Environment.NewLine, sproperty, ue.Properties(sproperty)(0)))
            Next
    
           
            ' test the update here ...
    
            If (ue.Properties.Contains("department")) Then
                ue.Properties("department").Value = "IT"
            Else
                ue.Properties("department").Add("IT")
            End If
    
            ue.CommitChanges()
            ue.RefreshCache()
            ue.Close()
    
        Catch ex As Exception
           
           debug.print (ex.Message)
    
        End Try
    

    The code seems to connect to the LDAP server and retrieve the correct user because I can see valid data being displayed from the ue.Properties.PropertyNames collection. The error is thrown on the "CommitChanges()" line. BTW: This demo program is a WinForms .NET 4.0 applicaiton I have tried it passing no credentials and passing valid domain credentials and I get the same " ... unwilling to process request." error. What am I doing wrong?

    B 1 Reply Last reply
    0
    • D David Mujica

      I'm trying to create a utility to perform a mass update of our Active Directory and all I get is the error, "Server is unwilling to process request." Below is my code:

      Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")

          Dim ds As New DirectorySearcher(de)
          ds.PropertiesToLoad.Add("department")
          ds.SearchScope = SearchScope.Subtree
      
          Dim ue As New DirectoryEntry   
          
          ds.Filter = String.Format("(SAMAccountName={0})", Me.tboxUserName.Text)
      
          Try
              ue = ds.FindOne.GetDirectoryEntry
      
              For Each sproperty As String In ue.Properties.PropertyNames
                  debug.print(String.Format("{0}{1} : {2} ", System.Environment.NewLine, sproperty, ue.Properties(sproperty)(0)))
              Next
      
             
              ' test the update here ...
      
              If (ue.Properties.Contains("department")) Then
                  ue.Properties("department").Value = "IT"
              Else
                  ue.Properties("department").Add("IT")
              End If
      
              ue.CommitChanges()
              ue.RefreshCache()
              ue.Close()
      
          Catch ex As Exception
             
             debug.print (ex.Message)
      
          End Try
      

      The code seems to connect to the LDAP server and retrieve the correct user because I can see valid data being displayed from the ue.Properties.PropertyNames collection. The error is thrown on the "CommitChanges()" line. BTW: This demo program is a WinForms .NET 4.0 applicaiton I have tried it passing no credentials and passing valid domain credentials and I get the same " ... unwilling to process request." error. What am I doing wrong?

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      According to http://forums.asp.net/t/1809557.aspx/1[^], the problem arises by using the wrong protocol: Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword") replace that with Dim de As New DirectoryEntry(**@"LDAP:\\**DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")

      D 1 Reply Last reply
      0
      • B Bernhard Hiller

        According to http://forums.asp.net/t/1809557.aspx/1[^], the problem arises by using the wrong protocol: Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword") replace that with Dim de As New DirectoryEntry(**@"LDAP:\\**DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")

        D Offline
        D Offline
        David Mujica
        wrote on last edited by
        #3

        Thank you so much. My program is now working. :thumbsup: I've been trying so many combinations that I must have overlooked the obvious.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups