Reuse of DB-API 2.0 cursors for multiple queries?

Discussion in 'Python' started by moreati, Jan 28, 2009.

  1. moreati

    moreati Guest

    Today, I used the adodbapi module against an SQL Server Express
    database. I was surprised to get an exception, when I attempted to
    submit a second query with my cursor object. The full session is
    below.

    With cx_Oracle I've become used to reusing a cursor for subsequent
    queries. The PEP doesn't specify either way, that I can see. Is this
    behaviour left to the implementation, or should I be able to expect a
    cursor is reusable?

    With thanks, Alex

    Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
    (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import adodbapi
    >>> conn = adodbapi.connect('Provider=SQLOLEDB.1;Data Source=.\\SQLEXPRESS;Initial Catalog=MYDATABBASE;Integrated Security=SSPI;User Instance=False;')
    >>> curs = conn.cursor()
    >>> curs.execute('select * from localview_roles')
    >>> curs.execute('select * from localview_roles')

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 713,
    in execut
    e
    self._executeHelper(operation,False,parameters)
    File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 664,
    in _execu
    teHelper
    self._raiseCursorError(DatabaseError,tracebackhistory)
    File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 474,
    in _raise
    CursorError
    eh(self.conn,self,errorclass,errorvalue)
    File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line 60,
    in standar
    dErrorHandler
    raise errorclass(errorvalue)
    adodbapi.adodbapi.DatabaseError:
    --ADODBAPI
    Traceback (most recent call last):
    File "C:\Python25\Lib\site-packages\adodbapi\adodbapi.py", line
    650, in _exec
    uteHelper
    adoRetVal=self.cmd.Execute()
    File "<COMObject ADODB.Command>", line 3, in Execute
    File "C:\Python25\lib\site-packages\win32com\client\dynamic.py",
    line 258, in
    _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
    retType, argTypes
    ) + args)
    com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft OLE
    DB Provider
    for SQL Server', u'Cannot create new connection because in manual or
    distribute
    d transaction mode.', None, 0, -2147467259), None)
    -- on command: "select * from localview_roles"
    -- with parameters: None
     
    moreati, Jan 28, 2009
    #1
    1. Advertising


  2. > Today, I used the adodbapi module against an SQL Server Express
    > database. I was surprised to get an exception, when I attempted to
    > submit a second query with my cursor object. The full session is
    > below.


    >>> curs.execute('select * from localview_roles')
    >>> curs.execute('select * from localview_roles')


    have you tried to curs.fetch() or fetchall() before the second execute?



    --
    дамјан ( http://softver.org.mk/damjan/ )

    Scarlett Johansson: You always see the glass half-empty.
    Woody Allen: No. I see the glass half-full, but of poison.
     
    Дамјан ГеоргиевÑки, Jan 28, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    5
    Views:
    534
    Steve C. Orr [MVP, MCSD]
    May 17, 2005
  2. Hylander

    To reuse or not to reuse....

    Hylander, Feb 26, 2004, in forum: Java
    Replies:
    0
    Views:
    421
    Hylander
    Feb 26, 2004
  3. code reuse and design reuse

    , Feb 7, 2006, in forum: C Programming
    Replies:
    16
    Views:
    1,024
    Malcolm
    Feb 12, 2006
  4. jacob navia

    To reuse or not to reuse

    jacob navia, Nov 5, 2006, in forum: C Programming
    Replies:
    19
    Views:
    529
    Dave Thompson
    Dec 18, 2006
  5. Greg

    reuse gridview for different sql queries

    Greg, Mar 20, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    159
Loading...

Share This Page