Searching with ADO

When developing ASP-based applications and Web Parts on a computer running Microsoft SharePoint Portal Server to perform searches you must use ServerXMLHTTP. Using ActiveX Data Objects (ADO) might cause Internet Information Services (IIS) to become unresponsive. ADO may be used for client applications.

The following example demonstrates how to use ActiveX Data Objects (ADO) to issue a search query for documents stored in a SharePoint Portal Server workspace.

On Error Resume Next

'Execute Query
Set conn = CreateObject("ADODB.Connection")
OnErrorExit "Error creating object: ADODB.Connection"
Set cmd = CreateObject("ADODB.Command")
OnErrorExit "Error creating object: ADODB.Command"
Set RS = CreateObject("ADODB.RecordSet")
OnErrorExit "Error creating object: ADODB.Recordset"

conn.ConnectionString = "provider=msdaipp.dso" 
conn.CommandTimeout = 0
conn.Open "http://myserver/myworkspace"
OnErrorExit "Error opening connection"

set cmd.ActiveConnection = conn
cmd.CommandText = "select ""DAV:displayname"" from scope('deep traversal of ""/myworkspace/documents""') where freetext('word doc')"
OnErrorExit "Error setting command properties"

RS.open cmd
OnErrorExit "Error executing query"

DumpRowset RS

''' DONE '''

Sub OnErrorExit (sMessage)
    If Err.Number <> 0 Then
        Msgbox sMessage
        Msgbox "Message '" & Err.Description & "' Number 0x" & Hex(Err.Number)
    End If
End Sub

Sub DumpRowset (RS)
    Dim i, j
    Dim sResult, sHead
    i = 0
    While Not RS.EOF
        i = i + 1
        sResult = ""
        sHead = i & ") "
        For j = 0 to RS.Fields.Count - 1 
            sResult = sResult & sHead & RS(j).Name & " : " & RS(j).Value & vbCRLF
            sHead = Space (Len(sHead))
        Next

        Msgbox sResult
        RS.MoveNext
    Wend

    Msgbox i & " Results."
End Sub

Searching with XMLHTTP