By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

ASP LDAP Query Error

P: n/a

I have an ASP page that retrieves user info. The page runs fine on XP
Pro IIS 5.1, however, when i try to run it from a server running W2k
Server SP4 or W2K3, it breaks and i get the following error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
Code:
--------------------
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
Set objNet = Server.CreateObject("WScript.Network")
strUserName = UCase(objNet.UserName)

' Use ADO to search Active Directory.
Set objCommand = Server.CreateObject("ADODB.Command")
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strBase = "LDAP://" & strDNSDomain & ""'<--Had to remove greater/less thans infront of LDAP and between "" because the forum didn't like it

' Filter on all user objects.
strFilter = "(& (objectCategory=person)(objectClass=user)(sAMAccou ntName=" & strUserName & "))"

' Specify attribute values to retrieve.
strAttributes = " distinguishedName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute
strDN = objRecordSet.Fields("distinguishedName").value

Set objUser = GetObject("LDAP://" & strDN)'<--Errors here
Response.Write "-- sAMAccountName: " & objUser.sAMAccountName
Response.Write "-- Department: " & objUser.Department
Response.Write "-- TelephoneNumber: " & objuser.telephoneNumber

Set objRootDSE = Nothing
Set objNet = Nothing
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
Set objRecordSet = Nothing
Set objUser = Nothing

--------------------

I have tried changing the following code:

Code:
--------------------

From This:

strDN = objRecordSet.Fields("distinguishedName").value

To this:

strDNTemp = objRecordSet.Fields("distinguishedName").value
For Each strValue in strDNTemp
strDN = strDN & strValue
Next

--------------------

Which works but then some fields are not returned i.e Department,
sAMAccount.
I'm pretty sure it has to do with IIS but not sure where or how to fix
it
Any help would be appreciated

--
sunmiester
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Jul 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.