5

I am trying to find a way to run an SQL query on the Windows Search Index.

This is possible quite easily using .NET or Powershell, but no matter what I do, I can't seem to make it work in Python.

I tried using PyODBC and riding on the JET4 driver, but got a whole bunch of errors. Then, I tried using the win32con client for an ADO connection, but that did not pan out as well.

I tried stating the provider as MSIDXS.1 or as Search.CollatorDSO as offered in some places and even tried accessing the EDB file directly, but with no luck.

Does anyone ever managed to do so, or knows what may be the issue?

For reference, I am attaching a link to a sample of Powershell and C# scripts doing this operation: - https://www.petri.com/how-to-query-the-windows-search-index-using-sql-and-powershell - https://msdn.microsoft.com/en-us/library/windows/desktop/ff684395(v=vs.85).aspx

I could use a VB script and approach it with the query as parameter, but it feels quite lame to me...

EDIT: I now seem to be connecting to the correct DB but get an error :

My code:

    conn = win32com.client.Dispatch('ADODB.Connection')
    #DSN = ('Provider=MSIDXS.1;Data Source=SYSTEMINDEX;')
    DSN = ('Provider=MSIDXS.1;Data Source=myCatalog;')
    conn.Open(DSN)
    rs = win32com.client.Dispatch(dispatch='ADODB.Recordset')
    strsql = r'SELECT 

The Error:

Traceback (most recent call last):
File "E:/Automation Scripts/123456/searchIndexQuery.py", line 48, in <module>
searchIndexConnector().ado()
File "E:/Automation Scripts/123456/searchIndexQuery.py", line 42, in ado
rs.Open(strsql, conn, 1, 3)
File "<COMObject ADODB.Recordset>", line 4, in Open
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Provider for Indexing Service', u"Incorrect syntax near '.'.  Expected ',', '.', FROM. SQLSTATE=42000 ", None, 0, -2147217900), None)

Thanks!

  • Did you ever resolve this? I got the queries to work and could iterate over the recordset but after 7500 or so records it would raise `3721 -2146824567 0x800A0E89 Data value is too large to be represented by the field data type.` – Arthur Dent Jun 09 '18 at 01:20
  • If it's any help, [here's my question](https://stackoverflow.com/q/50770172/9760446) which shows I implemented this (it works but then fails with a different error than the one here). – Arthur Dent Jun 09 '18 at 02:35

0 Answers0