I am trying to retrieve data about a user using an ADO/LDAP query from my ASP page (classic ASP, not ASP .NET). I am connecting to an Active Directory server over LDAP on port 636 (SSL). However I get a "Table does not exist." error. The credentials and connection details I am using are correct as I have tried connecting using an LDAP client and it works fine, but my code in ASP it fails. I have tried many permutations of the code and I aways get the same error! The Web server and LDAP server are at different locations and on different domains.
Here is the code (sensitive details replaced with X's):
<%
Option Explicit
Dim ADsPath
Dim cn
Dim com
Dim rs
' Set the path
ADsPath = "LDAP://XXX.XXX.XXX.XXX:636/OU=Users,OU=XXXX,DC=XXXX,DC=XXXX,DC=XXX"
Set cn = CreateObject("ADODB.Connection")
cn.Provider = "ADsDSOObject"
cn.Properties("User ID") = "uid=XXXX,OU=Users,OU=XXXX,DC=XXXX,DC=XXXX,DC=XXX"
cn.Properties("Password") = "XXXX"
' Set flag indicating SSL
cn.Properties("ADSI Flag") = 34
cn.Open "ADSI"
Set com = CreateObject("ADODB.Command")
Set com.ActiveConnection = cn
' Open recordset
com.CommandText = "<" & ADsPath & ">;(CN=XXXX);givenName,sn,mail;base"
Set rs = com.Execute ' *** CAUSES ERROR ***
If Not rs.EOF Then
Response.Write rs("givenName") & " " & rs("sn") & " - " & rs("mail")
End If
rs.Close
Set rs = Nothing
%>
Here is the code (sensitive details replaced with X's):
<%
Option Explicit
Dim ADsPath
Dim cn
Dim com
Dim rs
' Set the path
ADsPath = "LDAP://XXX.XXX.XXX.XXX:636/OU=Users,OU=XXXX,DC=XXXX,DC=XXXX,DC=XXX"
Set cn = CreateObject("ADODB.Connection")
cn.Provider = "ADsDSOObject"
cn.Properties("User ID") = "uid=XXXX,OU=Users,OU=XXXX,DC=XXXX,DC=XXXX,DC=XXX"
cn.Properties("Password") = "XXXX"
' Set flag indicating SSL
cn.Properties("ADSI Flag") = 34
cn.Open "ADSI"
Set com = CreateObject("ADODB.Command")
Set com.ActiveConnection = cn
' Open recordset
com.CommandText = "<" & ADsPath & ">;(CN=XXXX);givenName,sn,mail;base"
Set rs = com.Execute ' *** CAUSES ERROR ***
If Not rs.EOF Then
Response.Write rs("givenName") & " " & rs("sn") & " - " & rs("mail")
End If
rs.Close
Set rs = Nothing
%>