Search code examples
pythonoledbpywin32connection-timeoutpywin

How to change command timeout in pywin32. 'Open' method


I've got the problem using pywin32 library and trying to connect to OLEDB.

Traceback

Traceback (most recent call last):
  File "<input>", line 35, in <module>
  File "<input>", line 31, in ado
  File "<COMObject ADODB.Recordset>", line 4, in Open
    the XML parser for analysis: the response Time for the XML for analysis request timed out before it was completed.', None, 0, -2147467259), None)

I've tried to add Connect Timeout=1000 to my connectionstring to no avail.

Code

import win32com.client
import pyodbc

conn = win32com.client.Dispatch(r'ADODB.Connection')
    DSN = CONNECTION_STRING
    conn.Open(DSN)

    rs = win32com.client.Dispatch(r'ADODB.Recordset')



        strsql = u"""
    select

        ...
        ...
        ...

        """

    h = rs.Open(strsql, conn,0,1)
    ts = rs.GetRows()
    conn.Close()
    return ts

I think that the problem is here:

h = rs.Open(strsql, conn,0,1)

I can't see which parameters should be passed to 'Open'. But I think it must have timeout parameter.

How can I change command timeout?


Solution

  • The problem is solved by adding:

    conn.CommandTimeout=3000