[egenix-users] Invalid cursor state

M.-A. Lemburg mal at egenix.com
Tue Jul 21 23:34:39 CEST 2009

Dan Fairs wrote:
>> Have you tried using the latest unixODBC version ?
>>> We're using the following software versions (from Ubuntu's package
>>> manager):
>>> unixODBC 2.2.11-16build2
>>> tdsodbc 0.82-3ubuntu1
>>> Zope 2.10.4 (built using buildout and sources, not Ubuntu packages)
>>> mxODBCZopeDA-1.0.10
>>> SQL Server 2005 Developer (also happens on SQL Server 2008 Express)
>>> Zope server is Ubuntu 8.10, though this also happens with 9.04.
>>> Python 2.4.5 (built from source)
> Just to follow up, we've tried the latest version of unixODBC (2.2.14)
> to no avail.
> We seem to be able to provoke the problem most reliably with Python code
> that does the following - using ZSQL methods, the same ZSQL method being
> used for each of the SELECTs:
> - Cause a row to be SELECTed from a table
> - UPDATE the same row
> - SELECT that same row again
> We'll then get the 'Invalid cursor state' message on the second select.
> Putting a time.sleep(1) before the update and the second select seems to
> prevent the error occurring. Googling the error does seem to indicate
> that this happens (at the C level) when two results handles are open
> simultaneously; the sleep seems to allow some opportunity for cleanup.

Are you using the ZSQL method from different threads ?

I assume you are running the UPDATE using a different ZSQL method,
right ?

It is possible that the ODBC driver tries to do some optimization
by keeping the result set and the cursor from the first SELECT
alive even after the Zope DA has closed it.

This would explain the invalid cursor state, since SQL Server
does not support multiple active statements on the same connection
unless you enable the MARS feature available in SQL Server 2005
and later:


(you can enable this via a connection parameter "Mars_Connection=on")

> Obivously not an ideal workaround, but it will at least keep us moving
> until we find a real solution (or re-jig the code flow so that
> select/update/select pattern doesn't happen).

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Jul 21 2009)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the egenix-users mailing list