Connecting to LDAP and querying for info

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • munkee
    Contributor
    • Feb 2010
    • 374

    Connecting to LDAP and querying for info

    Hi All,

    Basically I have been destroying my brain trying to work out how to connect to the LDAP server at work with access to search for info and import.

    I have a couple of questions. Firstly, what is the difference between LDAP and Active Directory? I can get basic information by running some vba to look up computernames real names etc from active directory but our LDAP contains more information such as addresses, telephone numbers but most importantly company specific information such as user id numbers for some of our systems which I will need to be querying.

    My issue is I cant get my head around creating an ADO connectiont o the LDAP to get this information. I have tried and failed numerous times and just reverted back to my Active Directory code.

    I have downloaded an LDAP viewer so I have the full server address etc to get down to the required level. The program brings this up as the server address:

    Code:
    ldap://scd2ldap.company.net:389/cn=GEEUER ANTJEE Z001VFMP S,l=SGX P,ou=E F,o=SUBCOMPANY,c=ES??base?(objectClass=*)
    (edited out company name etc)

    But I can never work out how exactly to put that part in to the code.

    Does anyone have an example of what is possible? And also how I would place the server in to code correctly. I think the server part is the major downfall.


    The code I have been using as a basis:
    Code:
      Sub returnit()
      Dim conn As ADODB.Connection
          Dim rs As ADODB.Recordset
    
          Set conn = New ADODB.Connection
          conn.Provider = "ADSDSOObject"
          conn.Open "ADs Provider"
    
          Set rs = conn.Execute( _
                "<LDAP://scd2ldap.COMPANY.net:389/o=SUBCOMPANY/ou=E F/cn=GEUEER ANTJEEE Z001VFMP S>;" _
                & "(objectClass=*);ADsPath,objectClass,cn;subtree")
    
          While Not rs.EOF
             Debug.Print rs.Fields(0).Value, rs.Fields(1).Value, _
                   rs.Fields(2).Value
             rs.MoveNext
          Wend
    
          conn.Close
    End Sub
    When I run the above code I get "Table does not exist"
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Not my area of expertise I'm afraid, try this and see if it helps ...

    Code:
    "<LDAP://scd2ldap.company.net:389/o=SUBCOMPANY/ou=E F/cn=GEEUER ANTJEE Z001VFMP S,l=SGX P,c=ES??base?>;" _
                & "(objectClass=*);ADsPath,objectClass,cn;subtree")

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Originally posted by Munkee
      Munkee:
      what is the difference between LDAP and Active Directory?
      LDAP is Lightweight Directory Access Protocol. As it says, it's a protocol that enables access to directory information.
      Active Directory is such a repository of directory information.

      You can use LDAP to interact with the Active Directory.

      Your other thread on this deals with the addressing issues in your code so I won't comment on that here.

      Comment

      Working...