Python DBI

Jimmy Retzlaff jimmy at
Fri Jan 3 12:15:22 CET 2003

ghostdog wrote:
> does the dbi and odbc supplied with the windows version of python
> calling of stored procedures like 
> mycursor.execute("sp_configure") ???
> if so, how do i get the results of sp_configure for example??
> it gives me "Invalid cursor state. in FETCH" when i use the following
> test = "sp_configure"
> cur.execute(test)
> result = cur.fetchall()
> print result

I'd guess you're working with SQL Server here. You can call stored
procedures using the odbc module included with win32all or with
ActivePython for Windows. If you have problems during the call to the
execute method (as opposed to the fetchall method as you spelled out
above) then you might also try the form:

test = "exec sp_configure"

The "Invalid cursor state..." problem is common when calling SQL Server
through ODBC, and not just with Python, I've seen it in VBScript via the
ADO-ODBC bridge and in C++ w/ MFC's ODBC support. One way around the
problem is to execute:

cur.execute("set nocount on")

This should be done soon after creating your cursor (i.e. before
executing any queries that exhibit the problem) and the effect will
persist for as long as you keep the cursor around.


More information about the Python-list mailing list