简体   繁体   中英

Error running windows search query on remote machine from C#

When I try to execute the following OLEDB command to programmatically query a search index on a remote machine (ALEC-HP) on the same domain I get the following error message

Unspecified error: -2147219688(0x80040718)

On the local machine the share \\\\ALEC-HP\\Simon.ALEKATEST.000 can be seen OK

SELECT System.ItemNameDisplay,SYSTEM.ITEMURL,System.DateModified, 
       System.ItemName, System.Search.Rank, System.Keywords,
       System.Search.AutoSummary,System.Search.GatherTime, System.ItemType  
FROM ALEC-HP.SystemIndex 
WHERE Scope='file://ALEC-HP/Simon.ALEKATEST.000'
AND CONTAINS(*,'"April Dwyer"',1033)

If the query is simplified to

SELECT  System.ItemNameDisplay,SYSTEM.ITEMURL,System.DateModified,
        System.ItemName, System.Search.Rank, System.Keywords, 
        System.Search.AutoSummary,System.Search.GatherTime, System.ItemType  
FROM ALEC-HP.SystemIndex 
WHERE CONTAINS(*,'"April Dwyer"',1033)

The same error occurs.

The query on the local index

SELECT  System.ItemNameDisplay,SYSTEM.ITEMURL,System.DateModified, 
        System.ItemName, System.Search.Rank, System.Keywords,
        System.Search.AutoSummary,System.Search.GatherTime, System.ItemType 
FROM "SYSTEMINDEX" 
WHERE CONTAINS(*,'"April Dwyer"',1033)

runs OK. Rebuilding the search index on ALEC-HP doesn't help.

The remote machine ALEC-HP runs Windows 7 and local search works OK on that machine.

  • Using a remote machine running Win 8.1 the remote index query runs OK.
  • I can't see any significant differences in permissions in the Search Index folders (C:\\Program Data\\Microsoft\\Search) on a remote machine where the query runs and a remote machine where it doesn't.
  • The Win 8.1 remote machine does not seem to have a search index folder C:\\Program Data\\Microsoft\\Search\\Data\\Applications\\Windows\\Projects\\SystemIndex\\Indexer\\CiFiles containing .ci files which is present on the Win 7 machine.
  • I think these are database files for the edb database (Jet Blue) used by Windows Search Indexer.
  • The local machine runs Windows 8.1.

Problem has now appeared on the search index of a remote machine running Win 8.1

For queries on a remote machine, the scope='File:UNCPath' clause must contain a UNC Path which is shared with the local machine (the path can use either forward or back slashes). Ie:

AND SCOPE='file://server/shareName'

If the path is not visible to the local machine, or the scope absent then the Unspecified Error appears. A more informative error message would be helpful!

ps Accessibility of the UNC Path from the local machine is not the whole story. On the remote machine the search location list includes the My Documents folders in two profile folders folder, which are both shared and have the same permissions for SYSTEM, which is the account used to run remote search. The share permissions are the same, but when one of the profile folders is used in the scope parameter, the Undefined Error appears. Search functions as expected for the other profile folder.

The error code 0x80040718 can be found in WindowsSearchErrors.h . It corresponds to:

QRY_E_INVALIDSCOPES
The scopes specified for the query were incorrectly formatted.

If you want to search the local catalog of another computer you must :

  • prefix the server name before the catalog
  • provide a valid UNC share in the SCOPE

From MSDN: SCOPE and DIRECTORY Predicates

To query the local catalog of a remote computer, include the computer name before the catalog and a Universal Naming Convention (UNC) path on the remote computer in the SCOPE or DIRECTORY clause.

You can find more information in Querying Process in Windows Search

Local and Remote Queries

You can execute your queries either locally or remotely. A local query using the FROM clause is shown in the following example. A local query queries the local SystemIndex catalog only.

 FROM SystemIndex 

A remote query using the FROM clause is shown in the following example. Adding ComputerName transforms the previous example into a remote query.

 FROM [<ComputerName>.]SystemIndex 

To retrieve an item by remote query, the item must meet the following requirements:

  • Be accessible via Universal Naming Convention (UNC) path.
  • Exist on the remote computer to which the client has access.
  • Have its security set to allow the client to have Read access.

After you share the folder(s), you can query the local index by specifying the remote computer's machine name in the FROM clause, and a UNC path on the remote computer in the SCOPE clause. A remote query using the FROM and SCOPE clauses is shown in the following example.

 SELECT System.ItemName FROM MachineName.SystemIndex WHERE SCOPE='file://MachineName/<path>' 

And the page URL Formatting Requirements documents some other variations for SQL for remote queries:

  • Local : file:///c:\\test\\example\\
  • Local : file:c:/test/example/
  • Local : c:\\test\\example\\
  • Remote : file:///\\\\server\\share\\
  • Remote : file://server/share/
  • Remote : \\\\server\\share\\

This means that:

  • your query must add server name in two places
  • the UNC in the SCOPE or DIRECTORY must be a valid share on the remote machine

For example:

SELECT System.ItemNameDisplay
FROM "ALEC-HP".SystemIndex
WHERE SCOPE='file://ALEC-HP/Simon.ALEKATEST.000'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM