Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP/ADO/LDAP query returning "Table does not exist." error

Status
Not open for further replies.

sergei77

Programmer
Aug 16, 2007
1
GB
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
%>
 
sounds like your adspath is off....response.write the variable sDomainAdsPath and see...

Code:
<%

dim cn 

Set RootDSE = GetObject("LDAP://RootDSE")
' get the root domain path on current network 
sDomainAdsPath =  RootDSE.Get("defaultNamingContext")

' debug 
' response.write sDomainAdsPath
' response.end

Set cn = CreateObject("ADODB.Connection")
cn.Provider = "ADsDSOObject"

myDomain = "tweety"
usracct  = "testacct"
userID   = myDomain & "\" & usracct
sPwd     = "1qazXSW@"

cn.Open "Data Source=Active Directory Provider;" & _
        "Provider=ADsDSOObject;" & _
        "User ID=" &userID & ";" & _
        "Password=" & sPwd

Set rs = cn.Execute("SELECT givenName,sn,mail " & _
                    "FROM 'LDAP://" & sDomainAdsPath & "' " & _
                    "WHERE objectCategory='user' " & _
                    "ORDER BY name")
  
if not rs.eof then
 do while not rs.eof
  response.write rs("givenname") & " " & rs("mail") & "<br>"
 rs.movenext
 loop
end if
rs.Close
Set rs = Nothing
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top