We help IT Professionals succeed at work.

The Active Directory datatype cannot be converted to/from a native DS datatype

kenchan2000
kenchan2000 asked
on
Medium Priority
1,546 Views
Last Modified: 2012-06-27
When I try to use the att. ASP script to retrieve a user profile from a W2k Adv server which is running
Web service to access another W2k Adv Server which is running Active Directory service. I always get
the incorrect datatype/schema and hence fails to collect the correct profile. Please help.

<%
Dim adminname, adminpwd
adminname = "cn=Administrator,cn=Users,dc=mydomain,dc=com"
adminpwd  = "adminpassword"

Dim sPrefix,sContainerDN, adsPath
sPrefix = "LDAP://ad.mydomain.com/"
sContainerDN = "OU=Person,DC=mydomain,DC=com"
adsPath = sPrefix & sContainerDN

If TRIM(Request.QueryString("userid"))="" Then Response.Write("Userid req'd"): Response.End
Dim varInfo()
Call GetInfo(TRIM(Request.QueryString("userid")), varInfo, Array("cn", "field1", "field2"))

'// get user information
Function GetInfo(ByVal strUserName, ByRef varInfo, ByRef params())
   
   Dim oADsObject
   Dim i

   On Error Resume Next
   Set oADsObject = GetObject(sPrefix & "CN=" & strUserName & "," & sContainerDN)
 
   Call oADsObject.GetInfo
   Dim pObj
   Set pObj = oADsObject.Next
   %>
   <table border=1>
     <tr>
       <td>
         Schema Name
       </td>
       <td>
         Data Type
       </td>
     </tr>
   <%
   While Not IsNull(pObj) And (Err.Number = 0)
     %>
     <tr>
       <td>
         <%=pObj.Name%>
       </td>
       <td>
         <%=pObj.ADsType%>
       </td>
     </tr>
     <%
     Set pObj = oADsObject.Next
   WEnd
   %>
   </table>
   <%
   Err.Clear
   
   Response.Write("<hr>")
   
   ReDim varInfo(UBound(params))
   %>
   <table border=1>
     <tr>
       <td>
         Schema Name
       </td>
       <td>
         Value
       </td>
     </tr>
   <%
   For i = LBound(params) To UBound(params)
       varInfo(i) = oADsObject.Get(params(i))
       Response.Write("<tr><td>")
       Response.Write(params(i))
       Response.Write("</td><td>")
       Response.Write(varInfo(i))
       Response.Write("</td></tr>")
   Next
   %>
   </table>
   <%
   Set oADsObject = Nothing

   If Err.Number <> 0 Then
       GetInfo = False
       Response.Write(Err.Number & ": " & Err.Description) 'always get "The Active Directory datatype
cannot be converted to/from a native DS datatype"
       Err.Clear
   Else
       GetInfo = True
   End If
   
End Function
%>

I've tried to run this script at that W2k Server running Active Directory service locally. It works
perfectly.
Comment
Watch Question

Michel SakrRounded IT Consultant / Projects manager / Cloud Consultant / IT Planning
CERTIFIED EXPERT

Commented:
Are you logging with an administrator account? (disable anonymous account)

Author

Commented:
Do you mean disabling anonymous inside IIS setting? I have tried that, but it doesn't work. Thx.
Rounded IT Consultant / Projects manager / Cloud Consultant / IT Planning
CERTIFIED EXPERT
Commented:
you need to connect as the domian administrator for that.. also you might need to add your domain name before your username you're loggin with (Domain\username)