tags:

views:

2124

answers:

3

Hello all,

I’ve got a problem with Visual Basic (6) in combination with LDAP. When I try to connect to an LDAP store, I always get errors like ‘Bad Pathname’ or ‘Table does not exist’ (depending on what the code looks like).

This is the part of the code I wrote to connect:

path = "LDAP://xx.xxx.xxx.xxx:xxx/"
Logging.WriteToLogFile "Test1", logINFO

Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADsDSOObject"
conn.Properties("User ID") = "USER_ID"
conn.Properties("Password") = "PASSWORD"
conn.Properties("Encrypt Password") = True
conn.Properties("ADSI Flag") = 34

Logging.WriteToLogFile "Test2", logINFO
conn.Open "Active Directory Provider"
Logging.WriteToLogFile "Test3", logINFO

Set rs = conn.Execute("<" & path & "ou=Some,ou=Kindof,o=Searchbase>;(objectclass=*);name;subtree")

Logging.WriteToLogFile "Test4", logINFO

The logfile shows “Test1” , “Test2”, “Test3” and then “Table does not exist”, so it’s the line “Set rs = conn.Execute(…)” where things go wrong (pretty obvious…).

In my code, I try to connect in a secure way. I found out it has nothing to do with SSL/certificates though, because it’s also not possible to establish an anonymous unsecured connection. Funny thing is: I wrote a small test app in .NET in five minutes. With that app I was able to connect (anonymously) and read results from the LDAP store, no problems at all.

Does anyone have any experience with the combination LDAP and VB6 and maybe know what could be the problem? I googled and saw some example code snippets, but unfortunately none of them worked (same error messages as result). Thanks in advance!

+1  A: 

I'm not sure how much help this will be, but I use this code to access Active Directory objects.

   Set oinfo = New ADSystemInfo
    sDomain = Split(oinfo.DomainDNSName, ".")
    '-- Get Datasets from the Active Directory

    '-- Connect to Active Directory in logged in domain
    con.Open "Provider=ADsDSOObject;Encrypt Password=False;Integrated Security=SSPI;Data Source=ADSDSOObject;Mode=Read;Bind Flags=0;ADSI Flag=-2147483648"

    '-- Query all serviceConnectionPoints in the Active Directory 
    '-- that contain the keyword "urn://tavis.net/TM/Database" 
    '--  and return the full path to the object

    Set rst = con.Execute("<LDAP://DC=" & sDomain(0) & ",DC=" & sDomain(1) & ">;(&(objectCategory=serviceConnectionPoint)(keywords=urn://tavis.net/TM/Database));Name, AdsPath;subTree")
Darrel Miller
A: 

That doesn't work unfortunately, I get the same error (bad pathname). I also tried connecting with the help of IADS objects, that didn't work either (property not found). Any ideas?

Is the machine you are running this from a member of the domain? Are you logged into a domain account?
Darrel Miller
+1  A: 

2 things:

  • The Open() method call takes additional parameters, server/username/password
  • The LDAP query you passed to Execute() should be:

    "<" & path & "ou=Some/ou=Kindof/o=Searchbase>;(objectclass=*);name;subtree"

AviD