Re: vbscript, searching Active directory using ADODB type mismatch error
From: Richard Mueller [MVP] (rlmueller-NOSPAM_at_ameritech.NOSPAM.net)
Date: 04/19/04
- Next message: Jerry Camel: "Secure Scripts"
- Previous message: Martin c: "More fun with Index Server"
- In reply to: Paul: "vbscript, searching Active directory using ADODB type mismatch error"
- Next in thread: Paul: "Re: vbscript, searching Active directory using ADODB type mismatch error"
- Reply: Paul: "Re: vbscript, searching Active directory using ADODB type mismatch error"
- Messages sorted by: [ date ] [ thread ]
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 --
- Next message: Jerry Camel: "Secure Scripts"
- Previous message: Martin c: "More fun with Index Server"
- In reply to: Paul: "vbscript, searching Active directory using ADODB type mismatch error"
- Next in thread: Paul: "Re: vbscript, searching Active directory using ADODB type mismatch error"
- Reply: Paul: "Re: vbscript, searching Active directory using ADODB type mismatch error"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|