473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

LDAP issue..no idea how to construct the connection

374 256MB
Hi all,

I am having trouble with connecting to my companies LDAP to retrieve userinfo. I can return basic information from my local area using the following connection settings:
Expand|Select|Wrap|Line Numbers
  1. Set oRoot = GetObject("LDAP://rootDSE")
  2. 'work in the default domain
  3. sDomain = oRoot.Get("defaultNamingContext")
  4. Set oDomain = GetObject("LDAP://" & sDomain)
  5. sBase = "<" & oDomain.ADsPath & ">"
However this is producing the server as being DC=ww007,DC=mycompany,DC=net. Which does not have available the same information as our company wide ldap.

I have use JXplorer to find my site within our huge directory (over 400k employees) and the connection would be:

Expand|Select|Wrap|Line Numbers
  1. ldap://scd2ldap.mycompany.net:389/cn=MCGUINNESS NAME Z002DTRW,l=NUR S,ou=E F,o=mycompany,c=GB??base?(objectClass=*)
The attributes available to me are vast such as gender/department/faxnumber etc etc.

I want to be able to enter the cn value and return all of the other attributes associated with that.

My attempted code has always failed and this is what I am using at the moment:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function UserInfo(LoginName As String) As String
  5. 'PURPOSE: Display information that is available in
  6. 'the Active Directory about a given user
  7.  
  8. 'PARAMETER: Login Name for user
  9.  
  10. 'RETURNS: String with selected information about
  11. 'user, or empty string if there is no such
  12. 'login on the current domain
  13.  
  14. 'REQUIRES: Windows 2000 ADSI, LDAP Provider
  15. 'Proper Security Credentials.
  16.  
  17. 'EXAMPLE: msgbox UserInfo("Administrator")
  18.  
  19. Dim conn As New ADODB.Connection
  20. Dim rs As ADODB.Recordset
  21. Dim oRoot As IADs
  22. Dim oDomain As IADs
  23. Dim sBase As String
  24. Dim sFilter As String
  25. Dim sDomain As String
  26.  
  27. Dim sAttribs As String
  28. Dim sDepth As String
  29. Dim sQuery As String
  30. Dim sAns As String
  31.  
  32. Dim user As IADsUser
  33.  
  34. On Error GoTo errhandler:
  35. Debug.Print
  36. 'Get user Using LDAP/ADO.  There is an easier way
  37. 'to bind to a user object using the WinNT provider,
  38. 'but this way is a better for educational purposes
  39. Set oRoot = GetObject("LDAP://rootDSE")
  40. 'work in the default domain
  41. sDomain = oRoot.Get("defaultNamingContext")
  42. Set oDomain = GetObject("LDAP://" & sDomain)
  43. sBase = "<" & oDomain.ADsPath & ">"
  44. 'Only get user name requested
  45. sFilter = "(&(objectCategory=person)(objectClass=user)(name=" _
  46.   & LoginName & "))"
  47. sAttribs = "adsPath"
  48. sDepth = "subTree"
  49.  
  50. sQuery = sBase & ";" & sFilter & ";" & sAttribs & ";" & sDepth
  51.  
  52. conn.Open _
  53.   "Data Source=Active Directory Provider;Provider=ADsDSOObject"
  54.  
  55. Set rs = conn.Execute(sQuery)
  56.  
  57. If Not rs.EOF Then
  58.     Set user = GetObject(rs("adsPath"))
  59.  
  60.     With user
  61.  
  62.     'if the attribute is not stored in AD,
  63.     'an error will occur.  Therefore, this
  64.     'will return data only from populated attributes
  65.     On Error Resume Next
  66.  
  67.     sAns = "First Name: " & .FirstName & vbCrLf
  68.     sAns = sAns & "Last Name " & .LastName & vbCrLf
  69.     sAns = sAns & "Employee ID: " & .EmployeeID & vbCrLf
  70.     sAns = sAns & "Title: " & .Title & vbCrLf
  71.     sAns = sAns & "Division: " & .Division & vbCrLf
  72.     sAns = sAns & "Department: " & .Department & vbCrLf
  73.     sAns = sAns & "Manager: " & .Manager & vbCrLf
  74.     sAns = sAns & "the name yo: " & .name & vbCrLf
  75.  
  76.     sAns = sAns & "Phone Number: " & .TelephoneNumber & vbCrLf
  77.     sAns = sAns & "Fax Number: " & .FaxNumber & vbCrLf
  78.  
  79.     sAns = sAns & "Email Address: " & .EmailAddress & vbCrLf
  80.     sAns = sAns & "Web Page: " & .HomePage & vbCrLf
  81.     sAns = sAns & "Last Login: " & .LastLogin & vbCrLf
  82.     sAns = sAns & "Last Logoff: " & .LastLogoff & vbCrLf
  83.    ' sAns = sAns & "test" & .GetInfo("gender") & vbCrLf
  84.     sAns = sAns & "test " & .Description & vbCrLf
  85.     sAns = sAns & "test " & .ADsPath & vbCrLf
  86.     sAns = sAns & "test11 " & .Class & vbCrLf
  87.     sAns = sAns & "test11emp " & .GraceLoginsAllowed & vbCrLf
  88.  
  89.     sAns = sAns & "Account Expiration Date: " _
  90.          & .AccountExpirationDate & vbCrLf
  91.  
  92.     'IN RC2, this returned 1/1/1970 when password
  93.     'never expires option is set
  94.     sAns = sAns & "Password Expiration Date: " _
  95.       & .PasswordExpirationDate
  96.  
  97.     End With
  98. End If
  99. UserInfo = sAns
  100. errhandler:
  101.  
  102. On Error Resume Next
  103. If Not rs Is Nothing Then
  104.     If rs.State <> 0 Then rs.Close
  105.     Set rs = Nothing
  106. End If
  107.  
  108. If Not conn Is Nothing Then
  109.     If conn.State <> 0 Then conn.Close
  110.     Set conn = Nothing
  111. End If
  112.  
  113. Set oRoot = Nothing
  114. Set oDomain = Nothing
  115. End Function
  116.  
  117.  
As stated this is not currently connecting to the company wide ldap as far as I can see, or atleast I am not understanding how to return company specifc attributes.
Anyone able to guide me here? I am complete stumped.
Nov 27 '10 #1
12 6100
NeoPa
32,556 Expert Mod 16PB
Unfortunately, since I left my last company I no longer have access to the work I did using LDAP on my domain controllers :-(

I remember I found a lot out from googling though - I particularly played with LDIFDE.Exe. A very powerful tool, but great care needed to avoid doing damage if using an Admin account.

I guess it's your original GetObject line that's faulty, but I'm not familiar enough with your setup, or of using LDAP outside my quite narrow requirements as they were, to point you much better I'm afraid.
Nov 27 '10 #2
munkee
374 256MB
I have been googling for days now and I feel sometimes I get what's going on and then other times it is all a confused mess. I think the fact that I cant get anything being returned when I try to connnect to the full directory is what is causing the most frustration.

I can't get my head around whether infact I am capable of getting all these extra company specific attributes using my local settings or whether they are only held by connecting to the full server. Intellisense (if thats the correct name) brings up the basic attributes when using the code pasted above, but as I said, its the company specific ones which never seem to return.
Nov 27 '10 #3
NeoPa
32,556 Expert Mod 16PB
Well, I'll be happy to share with you the work I did on this if I ever manage to get a copy of it, but it sounds like your domain/forest setup may be more complicated than mine was so you need to determine exactly how that works before anything I can give you will help too much I suspect.

The bottom line is that even with my old code, I needed a thorough understanding of what was what as far as servers and domain were concerned before I could use the concepts in anger.
Nov 27 '10 #4
munkee
374 256MB
I have just taken a look at the basic information using dsquery.

What I found is infact I can search within my ww007 server and find myself (obviously) which leads me on to two conclusions.

Firstly I was able to find that I can do an advanced search which has within it all of the company attributes which I require.

Secondly this now means that I do not need to connect to the overall company wide activedirectory i.e. scd2ldap.company.net , I can simply use the local binding I get due to being connected to the ww007 server (where all the users are that I require further info on).

However this does mean I need to understand how to obtain these other attributes.

As stated earlier I am able to return the basics, following on from what the vba help brings up when querying user attributes, however I need to find out how to get the non standard attributes out of the AD.


Expand|Select|Wrap|Line Numbers
  1. With user 
  2.  
  3.     sAns = "First Name: " & .FirstName & vbCrLf 
  4.     sAns = sAns & "Last Name " & .LastName & vbCrLf 
  5.  
This is the part of the code I use to get the normal attributes. But it will not bring up the others held within the AD that seem to be more company specific. Is there a different object I need to be referencing other than "user" I wonder..
Nov 27 '10 #5
NeoPa
32,556 Expert Mod 16PB
You need to find your way around the fundamental structure of course. Users are items, but there are various other items as well that you can probably discover by playing with the ADUC (Active Directory Users and Computers) plug-in. There are other AD plug-ins that give other info of course, but I found most of what I needed in ADUC.

To find the correct LDAP names for all the available properties I used LDIFDE.Exe to do a full (or partial) dump of a folder that I'd identified in my search through ADUC (The main Users folder where all my users were stored). With that dump I had a pretty full list of all the user attributes I needed. The top level structure of the tree is also quite available by searching I expect, but the specific attributes are another matter. I came across one or two, but the list I found in the LDIFDE dump was much fuller, even if without any particular explanations. You can work out most of the ones you need though, and test them by putting dummy values in on a dummy user. If the value changes then you know which attribute name reflects the item you changed.
Nov 27 '10 #6
munkee
374 256MB
NeoPa I have done a bit more digging around the attributes available to me.

It seems the global AD (named scd2) contains more information than our local AD (within my ww007 server for the offices). After running a search on myself using ADUC I am presented with my profile on the ww007 server which containes quite a lot of attributes but only around 10 of the 40 contain any data.

These attributes are similar to those on the corporate directory (scd2) but the scd2 has a lot more attributes, which I have viewed using some free LDAP browsing software (such things as gender etc. which the local AD doesnt seem to have as an attribute at all.)

This leaves me with the issue that the information I need is definitely on this corportate directory.

I have used the following code succesfully on my local directory to return its attributes:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSample_Click()
  2. 'Code to retrieve information from the Active Directory given the SN.
  3. 'Change dc=cityofcomputer and OU information.
  4. 'Searches in givenName if not found in SN AD field.
  5. Dim varInfo As Variant
  6. varInfo = ""
  7. Dim LN As Variant
  8. LN = InputBox("Enter SN:")
  9. Const ADS_SCOPE_SUBTREE = 2
  10.  
  11. Set objConnection = CreateObject("ADODB.Connection")
  12. Set objCommand = CreateObject("ADODB.Command")
  13. objConnection.Provider = "ADsDSOObject"
  14. objConnection.Open "Active Directory Provider"
  15. Set objCommand.ActiveConnection = objConnection
  16.  
  17. objCommand.Properties("Page Size") = 1000
  18. objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
  19.  
  20. objCommand.CommandText = _
  21.     "SELECT Name,AdsPath,givenName,SN,title,telephonenumber,Department,OU, CN, initials, displayname, " _
  22.     & "userAccountControl, sAMAccountName, distinguishedName, physicalDeliveryOfficeName, mail,wWWHomePage,homePhone,pager,mobile,ipPhone,Info  " _
  23.         & "FROM 'LDAP://OU=550,OU=Depts,OU=Users,OU=E7GN,OU=E7G,OU=EUsers,DC=ww007,DC=company,DC=net' WHERE " _
  24.             & "objectCategory='user' And SN= '" & LN & "'"
  25.  
  26. 'objCommand.CommandText = _
  27. '    "SELECT Name,AdsPath,givenName,SN,title,telephonenumber,Department,OU, CN, initials, displayname, " _
  28. '    & "physicalDeliveryOfficeName, mail,wWWHomePage,homePhone,pager,mobile,ipPhone,Info  " _
  29. '        & "FROM 'LDAP://dc=cityofmadison,dc=com' WHERE " _
  30. '            & "objectCategory='user' And SN= '" & LN & "'"
  31.  
  32. 'objCommand.CommandText = _
  33. '    "SELECT * FROM 'LDAP://dc=cityofmadison,dc=com' WHERE " _
  34. '            & "objectCategory='user' And SN = '" & LN & "'"
  35.  
  36. Set objrecordset = objCommand.Execute
  37. If objrecordset.EOF And objrecordset.BOF Then
  38.     objrecordset.Close
  39.     MsgBox "No Records match...Trying searching on GivenName."
  40. objCommand.CommandText = _
  41.     "SELECT Name,AdsPath,givenName,SN,title,telephonenumber,Department,OU, CN, initials, displayname, " _
  42.     & "userAccountControl, sAMAccountName, distinguishedName, physicalDeliveryOfficeName, mail,wWWHomePage,homePhone,pager,mobile,ipPhone,Info  " _
  43.         & "FROM 'LDAP://OU=550,OU=Depts,OU=Users,OU=E7GN,OU=E7G,OU=EUsers,DC=ww007,DC=company,DC=net' WHERE " _
  44.             & "objectCategory='user' And givenname = '" & LN & "'"
  45.     Set objrecordset = objCommand.Execute
  46.     If objrecordset.EOF And objrecordset.BOF Then
  47.         MsgBox "No records found matching on GivenName."
  48.         objrecordset.Close
  49.         Exit Sub
  50.     End If
  51. End If
  52. objrecordset.MoveFirst
  53.  
  54. Do While Not objrecordset.EOF
  55. varInfo = "Name = " & objrecordset.Fields("Name").Value & Chr(10) _
  56.     & "AdsPath = " & objrecordset.Fields("Adspath").Value & Chr(10) _
  57.     & "givenName = " & objrecordset.Fields("givenName").Value & Chr(10) _
  58.     & "SN = " & objrecordset.Fields("SN").Value & Chr(10) _
  59.     & "title = " & objrecordset.Fields("title").Value & Chr(10) _
  60.     & "Telephonenumber = " & objrecordset.Fields("telephonenumber").Value & Chr(10) _
  61.     & "Department = " & objrecordset.Fields("Department").Value & Chr(10) _
  62.     & "CN = " & objrecordset.Fields("CN").Value & Chr(10) _
  63.     & "OU = " & objrecordset.Fields("OU").Value & Chr(10) _
  64.     & "Displayname = " & objrecordset.Fields("Displayname").Value & Chr(10) _
  65.     & "Initials = " & objrecordset.Fields("Initials").Value & Chr(10) _
  66.     & "PhysicalDeliveryOfficeName = " & objrecordset.Fields("PhysicalDeliveryOfficeName").Value & Chr(10) _
  67.     & "Mail = " & objrecordset.Fields("Mail").Value & Chr(10) _
  68.     & "wWWHomePage = " & objrecordset.Fields("wWWHomePage").Value & Chr(10) _
  69.     & "HomePhone = " & objrecordset.Fields("HomePhone").Value & Chr(10) _
  70.     & "Pager = " & objrecordset.Fields("Pager").Value & Chr(10) _
  71.     & "Mobile = " & objrecordset.Fields("Mobile").Value & Chr(10) _
  72.     & "ipPhone = " & objrecordset.Fields("ipPhone").Value & Chr(10) _
  73.     & "Info = " & objrecordset.Fields("Info").Value & Chr(10) _
  74.     & "distinguishedName = " & objrecordset.Fields("distinguishedName").Value & Chr(10) _
  75.     & "sAMAccountName = " & objrecordset.Fields("sAMAccountName").Value & Chr(10) _
  76.     & "userAccountControl (512=unlocked <>512=locked) = " & objrecordset.Fields("userAccountControl").Value & Chr(10) _
  77.    ' & "userPrincipalName = " & objrecordset.Fields("userPrincipalName").Value & Chr(10) _
  78.  
  79. MsgBox varInfo
  80. objrecordset.MoveNext
  81. Loop
  82. End Sub
However when I replace:

Expand|Select|Wrap|Line Numbers
  1. 'LDAP://OU=550,OU=Depts,OU=Users,OU=E7GN,OU=E7G,OU=EUsers,DC=ww007,DC=company,DC=net' 
With:

Expand|Select|Wrap|Line Numbers
  1. l=NUT S,ou=E F,o=SIEMENS,c=GB,dc=scd2ldap,dc=company,dc=net
Where I know using the ldap browser software that NUT S is the container for all users I just keep getting table does not exist errors :|
Nov 28 '10 #7
munkee
374 256MB
After 5 hours of testing and messing around I have finally brought up some sign of progress!

This does not currently do what I want but it has finally shown I can query the corporate directory (world wide) using code.

The following checks my local site for female employees ( OI OI! ):

Expand|Select|Wrap|Line Numbers
  1. Sub gogdfgdf()
  2.  
  3.  
  4. Set ado = CreateObject("ADODB.Connection")
  5. ado.Provider = "ADSDSOObject"
  6. ado.Properties("User ID") = ""
  7. ado.Properties("Password") = ""
  8. ado.Properties("Encrypt Password") = False
  9. ado.Open "ADS-Anon-Search"
  10.  
  11. 'ServerName = "scd2ldap.mycompany.net/cn=Z0003PJO,l=NUT S,ou=E F,o=mycompany,c=GB"
  12. ServerName = "scd2ldap.mycompany.net/l=NUT S,ou=E F,o=mycompany,c=GB"
  13. filterStr = "(&(objectclass=scdPerson)(gender=F))"
  14.  
  15. Set objectList = ado.Execute("<LDAP://" & ServerName & ">;" & filterStr & ";ADsPath;SubTree")
  16.  
  17. While Not objectList.EOF
  18.     Debug.Print objectList.Fields(0).Value
  19.     objectList.MoveNext
  20. Wend
  21.  
  22.  
  23.  
  24. End Sub
  25.  
I found that one of the objectclasses were titled scdPerson where most other scripts/AD's use "user". Hopefully by changing this class object I can discover all of the attributes as NeoPa stated earlier.

At the moment also the data is presented as:

LDAP://scd2ldap.mycompany.net/cn=SANDRA Z002WERNP2H,l=NUT S,ou=E F,o=mycompany,c=GB
LDAP://scd2ldap.mycompany.net/cn=ANNE Z002NUEWRYD,l=NUT S,ou=E F,o=mycompany,c=GB
LDAP://scd2ldap.mycompany.net/cn=KIRSTY Z000WR3PIY,l=NUT S,ou=E F,o=mycompany,c=GB
LDAP://scd2ldap.mycompany.net/cn=MARY Z000R3PIZ,l=NUT S,ou=E F,o=mycompany,c=GB

I will need to work on outputting this in a more userfriendly manner that I can use in my databases.
Nov 28 '10 #8
munkee
374 256MB
Ok I am much further on now and I think I am on to my final issue.

I use the following function to do a debug.print of info from the corporate directory based on the second name of the person I want to find:

Expand|Select|Wrap|Line Numbers
  1. Public Function UserInfo12(LoginName As String) As String
  2.  
  3. Dim rs As ADODB.Recordset
  4. Dim sBase As String
  5. Dim sFilter As String
  6. Dim sDomain As String
  7. Dim sAttribs As String
  8. Dim sDepth As String
  9. Dim sQuery As String
  10. Dim sAns As String
  11. Dim user As IADsUser
  12. Dim counter As Integer
  13. On Error GoTo ErrHandler:
  14.  
  15. Set ado = CreateObject("ADODB.Connection")
  16. ado.Provider = "ADSDSOObject"
  17. ado.Properties("User ID") = ""
  18. ado.Properties("Password") = ""
  19. ado.Properties("Encrypt Password") = False
  20. ado.Open "ADS-Anon-Search"
  21.  
  22. servername = "scd2ldap.mycompany.net/l=NUT S,ou=E F,o=mycompany,c=GB"
  23.  
  24. sBase = "<LDAP://" & servername & ">"
  25. sFilter = "(&(objectClass=*)(cn=" & LoginName & "))"
  26. sAttribs = "adsPath"
  27. sDepth = "subTree"
  28.  
  29. sQuery = sBase & ";" & sFilter & ";" & sAttribs & ";" & sDepth
  30.  
  31.  
  32. Set rs = ado.Execute(sQuery)
  33.  
  34.  
  35. Do While Not rs.EOF
  36. Set user = GetObject(rs("adsPath"))
  37.  
  38. 'Debug.Print rs.RecordCount
  39. 'set counter to 0 before looping
  40. With user
  41.  
  42. On Error Resume Next
  43.  
  44. sAns = "Gender: " & .gender & vbCrLf
  45. sAns = sAns & "Display Name:" & .DisplayName & vbCrLf
  46. sAns = sAns & "Company:" & .company & vbCrLf
  47. sAns = sAns & "Department:" & .departmenttext & vbCrLf
  48. sAns = sAns & "Locality:" & .localitynational & vbCrLf
  49. sAns = sAns & "E mail:" & .mail & vbCrLf
  50. sAns = sAns & "Function:" & .mainfunction & vbCrLf
  51. sAns = sAns & "Phone:" & .mobile & vbCrLf
  52. sAns = sAns & "GID:" & .tcgid & vbCrLf
  53. sAns = sAns & "CN:" & .CN & vbCrLf
  54. sAns = sAns & "Cost unit location:" & .costlocationunit & vbCrLf
  55. sAns = sAns & "Cost location:" & .costlocation & vbCrLf
  56. sAns = sAns & "Nick name:" & .nickname & vbCrLf
  57. sAns = sAns & "title:" & .Title & vbCrLf
  58. sAns = sAns & "Organisation:" & .o & vbCrLf
  59. End With
  60. Debug.Print sAns
  61. 'UserInfo12 = sAns
  62. rs.MoveNext
  63. Loop
  64.  
  65.  
  66.  
  67. 'uncomment below to return function value
  68. 'UserInfo12 = sAns
  69. 'Debug.Print sAns
  70. ErrHandler:
  71.  
  72. On Error Resume Next
  73. If Not rs Is Nothing Then
  74. If rs.State <> 0 Then rs.Close
  75. Set rs = Nothing
  76. End If
  77.  
  78. If Not ado Is Nothing Then
  79. If ado.State <> 0 Then ado.Close
  80. Set ado = Nothing
  81. End If
  82.  
  83.  
  84. End Function
However the function only returns 1 value when I try to re-implement the functions return value. The debug.print line prints out 5 records since there are multiple people with the same second name.
Nov 28 '10 #9
NeoPa
32,556 Expert Mod 16PB
Munkee:
Expand|Select|Wrap|Line Numbers
  1. l=NUT S,ou=E F,o=SIEMENS,c=GB,dc=scd2ldap,dc=company,dc=net
Should it be l=NUT S, or ou=NUT S,? Unfortunately I have nothing here to test on so everything I say has to be from memory, and this work was all a few years ago now.
Nov 28 '10 #10
NeoPa
32,556 Expert Mod 16PB
Munkee:
The following checks my local site for female employees ( OI OI! ):
I had to laugh :-D What more do you need? I almost ask.
Munkee:
However the function only returns 1 value when I try to re-implement the functions return value.
I'm afraid I never accessed this via ADODB. Your code is not familiar to me, and I don't know the circumstances under which rs.EOF would be set TRUE (thereby ending your loop). I would suggest looking there though, or even debugging through the code to see exactly where it differs from your expectations (See Debugging in VBA).

I would also suggest looking into indenting of code. I'm not sure why an experienced programmer such as yourself would not indent their code, but if it's not something you've come across then I seriously suggest you look into it. It not only makes it very much easier for other coders to review your work, but it also makes it easier for you to see what bits of code go with what. Non-indented code is so much harder to work with. Only incorrectly indented code is harder (of which I'm sorry to say we see a fair bit of in some of our questions).

Lastly, what a good job you've made already, digging into this notoriously difficult subject. Not everyone sticks at it long enough to get results. Good luck in your ongoing endeavours.
Nov 28 '10 #11
munkee
374 256MB
Thank you for all of the flattery, experienced programmer I am far from! but I do like to research a good challenge. I like to think the vast majority of my code resembles that of franken-vba where I seem to have become quite proficient at bolting parts of every one elses together and stitching it all up to work.


I have some very bad habits which I need to get out of, such as remembering to indent.. and removing redundant code.

Anyway after yet more digging the final result is nearly there and the thread can come to an end:

Expand|Select|Wrap|Line Numbers
  1. Public Function UserInfoo(LoginName As String) As String
  2.  
  3. Dim rs As ADODB.Recordset
  4. Dim sBase As String
  5. Dim sFilter As String
  6. Dim sDomain As String
  7. Dim sAttribs As String
  8. Dim sDepth As String
  9. Dim sQuery As String
  10. Dim sAns As String
  11. Dim user As IADsUser
  12. Dim counter As Integer
  13. Dim bigstring As String
  14. Dim strHeaders As String
  15.  
  16. On Error GoTo ErrHandler:
  17.  
  18. Set ado = CreateObject("ADODB.Connection")
  19. ado.Provider = "ADSDSOObject"
  20. ado.Properties("User ID") = ""
  21. ado.Properties("Password") = ""
  22. ado.Properties("Encrypt Password") = False
  23. ado.Open "ADS-Anon-Search"
  24.  
  25. servername = "scd2ldap.mycompany.net/l=NUT S,ou=E F,o=SIEMENS,c=GB"
  26.  
  27. sBase = "<LDAP://" & servername & ">"
  28. sFilter = "(&(objectClass=*)(cn=" & LoginName & "))"
  29. sAttribs = "adsPath"
  30. sDepth = "subTree"
  31.  
  32. sQuery = sBase & ";" & sFilter & ";" & sAttribs & ";" & sDepth
  33.  
  34.  
  35. Set rs = ado.Execute(sQuery)
  36. strHeaders = "Gender;Display Name;Company;Department;Locality;E mail;function;phone;GID;CN;cost unit location;costunit;nickname;title;organisation;"
  37.  
  38. Do Until rs.EOF
  39. Set user = GetObject(rs("adsPath"))
  40. sAns = ""
  41. 'Debug.Print rs.RecordCount
  42. 'set counter to 0 before looping
  43. With user
  44. 'need some error coding for IF IS NULL then leave BLANK value in there. THis will stop the stuff displaying crap in the listbox
  45. On Error Resume Next
  46. sAns = sAns & .gender & ";" & .DisplayName & ";" & .Company & ";" & .departmenttext & ";" & .localitynational & ";" & .mail & ";" _
  47. & .mainfunction & ";" & .mobile & ";" & .tcgid & ";" & .CN & ";" & .costlocationunit & ";" & .costlocation & ";" & .nickname & ";" _
  48. & .Title & ";" & .o & ";"
  49. End With
  50. Forms.form1.listbox1.AddItem (sAns)
  51. rs.MoveNext
  52. Loop
  53. bigstring = strHeaders & sAns
  54. 'bigstring = strHeaders & sAns
  55. Debug.Print bigstring
  56. Forms.form1.listbox1.ColumnCount = 16
  57. Forms.form1.listbox1.RowSourceType = "Value List"
  58. Forms.form1.listbox1.ColumnHeads = True
  59. 'Forms.form1.listbox1.RowSource = bigstring
  60. 'uncomment below to return function value
  61.  
  62. 'Debug.Print sAns
  63. ErrHandler:
  64.  
  65. On Error Resume Next
  66. If Not rs Is Nothing Then
  67. If rs.State <> 0 Then rs.Close
  68. Set rs = Nothing
  69. End If
  70.  
  71. If Not ado Is Nothing Then
  72. If ado.State <> 0 Then ado.Close
  73. Set ado = Nothing
  74. End If
  75.  
  76.  
  77. End Function
  78.  
Function will output to a listbox showing all records within the recordset using the very simple .additem within the loop. Now for the tidying up!
Nov 28 '10 #12
NeoPa
32,556 Expert Mod 16PB
Munkee:
franken-vba
I ROFLed (well, guffawed loudly anyway. I hope I didn't wake the wife).

Good for you on finding the solution. I feel a bit like a tutor - where I was unable to tell you any answers (in my case bacause I had no access to any) but only give a few bare tips and send you on your way to flesh them out into a workable solution. I'm very pleased that you managed to in the end. Congratulations :-)
Nov 28 '10 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bonj | last post by:
Like a web app can store its connection string in the web.config file, can a windows forms or console app or windows service store its connection string in app.config? Is it advisable? I know...
2
by: Tdar | last post by:
Sorry for the dup post but looking for a response and this is being posted under my MSDN managed newsgroups handle and in a different newsgroup Hi, As I said in the past post I am using this...
37
by: sam44 | last post by:
Hi, At startup the user log on and chooses the name of a client from a dropdownlist, which then changes dynamically the connection string (the name of the client indicates which database to use)....
3
by: mbasil77 | last post by:
I'm trying to port a piece of Java LDAP conneciton code to DOTNET. I've done LDAP in DOTNET before, but I keep getting a very strange message. The Java code looks like: public static boolean...
2
by: anirudh lokray | last post by:
Hi friends.... I am working on a C# application with connects to the SQL Server 2000 database giving the server name, username, password, max pool size, database name as the parameters. When i...
4
by: shofu_au | last post by:
Hi Group, A question about threads and asynchronous TCP sockets. In the attached code, even if the host TCP server is not running my code reports that the connection has been established. ...
2
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post by:
Hi, I have recieved the following error in an application: "Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occured because all...
2
by: nidhijani | last post by:
Hey giv me some idea abt connection of an aspx form wth SQL Server2005 in .net 2005
1
by: Nullabee | last post by:
Hi All. I used to connect to a DB2 database on an iSeries (V5R2) through DB2 Connect 8.2 PE. On my new PC, I installed DB2 Database 9, and got no mention of any licensing problems, until I tried...
1
by: kmcq | last post by:
I've contacted my host and they have no idea what connection string I need to use to access the MS SQL database we have running on their equipment. I'm trying to connection from ASP using OLE. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.