如何使用VB6连接到LDAP存储
时间:2020-03-06 14:32:19 来源:igfitidea点击:
我将Visual Basic(6)与LDAP结合使用时遇到了问题。当我尝试连接到LDAP存储时,总是会收到错误消息,例如Bad Pathname或者Table不存在(取决于代码的样子)。
这是我编写的连接代码的一部分:
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
日志文件显示Test1,Test2,Test3,然后不存在Table,因此它在Set rs = conn.Execute()行中出了问题(非常明显)。
在我的代码中,我尝试以安全的方式进行连接。我发现它与SSL /证书无关,因为它也无法建立匿名的不安全连接。有趣的是:我在五分钟内用.NET编写了一个小型测试应用程序。使用该应用程序,我能够(匿名)连接并读取LDAP存储中的结果,完全没有问题。
是否有人对LDAP和VB6组合有任何经验,也许知道可能是什么问题?我在Google上搜索并看到了一些示例代码片段,但不幸的是它们都不起作用(结果是相同的错误消息)。提前致谢!
解决方案
我不确定这将有多少帮助,但是我使用此代码访问Active Directory对象。
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")
2件事:
- " Open()"方法调用采用其他参数,服务器/用户名/密码
- 我们传递给Execute()的LDAP查询应为:
"<" & path & "ou=Some/ou=Kindof/o=Searchbase>;(objectclass=*);name;subtree"