Re: vbscript, searching Active directory using ADODB type mismatch error

From: Richard Mueller [MVP] (rlmueller-NOSPAM_at_ameritech.NOSPAM.net)
Date: 04/19/04


Date: Mon, 19 Apr 2004 10:23:21 -0500

Paul wrote:

> I have taken the following script from the Searching Active Diectory Page.
It works when I echo the name but when I try to echo the decsription or
homedirectory I get "Microsoft VBScript runtime error: Type mismatch". I
know that the names of the fields I am querying are correct since if I enter
an invalid field name I get a different error message.
>
> Thank You,
>
> Paul
>
> Set objConnection = CreateObject("ADODB.Connection")
> objConnection.Open "Provider=ADsDSOObject;"
>
> Set objCommand = CreateObject("ADODB.Command")
> objCommand.ActiveConnection = objConnection
>
> objCommand.CommandText = _
>
"<LDAP://dc=test,dc=com>;(objectCategory=user);name,homedirectory,descriptio
n;subtree"
> Set objRecordSet = objCommand.Execute
>
> While Not objRecordSet.EOF
> 'Wscript.Echo objRecordSet.Fields("name")
> 'Wscript.Echo objRecordSet.Fields("homedirectory")
> Wscript.Echo objRecordSet.Fields("description")
> objRecordSet.MoveNext
> Wend
>
> objConnection.Close
>
Hi,

You can use the TypeName function to troubleshoot problems when you get
"type mismatch" errors. In this case, the values can be retrieved from the
recordset, but the Wscript.Echo command cannot handle them. The Name
property method always returns a string value, so that is no problem.
However, if either homeDirectory or description does not have a value, the
recordset field is "Null", which Wscript.Echo cannot handle. You can test
with the IsNull function. In addition, the description attribute is
technically a multi-valued attribute, although the system treats it as
single valued everywhere else. With ADO, you must enumerate the collection
of values (there is always only one string or none). Again, you must test
for the "Null" condition. I got your While loop to work as follows:

While Not objRecordSet.EOF
  strName = objRecordSet.Fields("name")
  Wscript.Echo "Name: " & strName
  strHome = objRecordSet.Fields("homedirectory")
  If IsNull(strHome) Then
    strHome = "none"
  End If
  Wscript.Echo "-- Home Directory: " & strHome
  arrDesc = objRecordSet.Fields("description")
  If IsNull(arrDesc) Then
    Wscript.Echo "-- Description: none"
  Else
    For Each strLine In arrDesc
      Wscript.Echo "-- Description: " & strLine
    Next
  End If
 objRecordSet.MoveNext
Wend

-- 
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--


Relevant Pages

  • Re: very very very very urgent and important
    ... At first it seemed to work fine in SeaMonkey 1.0.5, but when entering the secure area this message occoured: ... "Microsoft VBScript runtime error '800a000d' ... Type mismatch: 'ubound' ...
    (comp.sys.mac.apps)
  • Re: Format Percent
    ... Microsoft VBScript runtime error '800a000d' ... WScript.Echo FormatPercent(vVal, 2) vVal = Null WScript.Echo FormatPercent ... to verify that the last line does indeed raise a Type mismatch ...
    (microsoft.public.scripting.vbscript)
  • RE: WMI to read DNS server properties script
    ... I ran this sample script against a W2K3 DNS server and got the following error: ... Microsoft VBScript runtime error: Type mismatch ... Any hints? ...
    (microsoft.public.windows.server.scripting)
  • Re: Delphi 2006 announced
    ... but their websites obviously as good as their thoughts as it told me Microsoft VBScript runtime error '800a000d' Type mismatch: 'CLng' /opinion/post_message.asp, ...
    (borland.public.delphi.non-technical)