tanrj / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

sp_spaceused doesn't work on ASE15 with pyodbc #137

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. db = pyodbc.connect(...)
2. c = db.cursor()
3. c.execute('sp_spaceused object_name')

What is the expected output? What do you see instead?

The expected output is a cursor containing the result set from the stored 
procedure.

Instead I get this:

>>> c.execute("{call sp_spaceused some_table}")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.ProgrammingError: ('42000', '[42000] [FreeTDS][SQL Server]SELECT INTO 
command not allowed within multi-statement transaction.\n (226) 
(SQLExecDirectW)')

What version of the product are you using? On what operating system?
2.1.7, freetds, Sybase ASE 15.

Please provide any additional information below.

Is there anything that can be done to not implicitly set up a transaction, as I 
expect is happening here? This also happens when autocommit is set to False.

Original issue reported on code.google.com by pedri...@gmail.com on 17 Nov 2010 at 8:43

GoogleCodeExporter commented 8 years ago
Autocommit defaults to False, you need to set it to true:

cnxn.autocommit = True
rows = c.execute("sp_spaceused object_name").fetchall()
cnxn.autocommit = False

or 

cnxn = pyodbc.connect(..., autocommit=True)
rows = ...

I've added something to the FAQ for this.  Thanks.

Original comment by mkleehammer on 20 Nov 2010 at 7:02