Closed GoogleCodeExporter closed 8 years ago
I am unable to duplicate this with Python 2.6, SQLServer 2005.
Just tested and I was able to run a stored procedure.
Can you please try the following:
import pyodbc
cstring='DRIVER={SQL Server};SERVER=myserver;DATABASE=mydb'
sqlcmd='exec sp_help \'sys.tables\''
conn=pyodbc.connect(cstring,)
csr=cn.cursor()
print "SQL is", sqlcmd
exec sp_help 'sys.tables'
csr.execute(sqlcmd)
recs=csr.fetchall()
print recs
It should give output similar to:
[(u'tables', u'sys', u'view', datetime.datetime(2007, 2, 10, 0, 23, 16, 57000))]
Original comment by todd.w.s...@gmail.com
on 22 Dec 2009 at 8:39
Hello,
We are facing the very same issue as the OP (connecting to SQL Server 2005 with
the
2008 native client driver).
running the same command as the one provided in your response does work, but
running
a home made stored procedure does not.
>>> c.execute('CREATE TABLE test_table (col1 int)')
>>> sp = '''CREATE PROCEDURE test_procedure2 AS
... BEGIN
... insert into test_table(col1) values(42);
... select * from test_table;
... END;'''
>>> c.execute(sp)
>>> c.fetchall()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "logilab\database\sqlserver.py", line 135, in fetchall
for row in self._cursor.fetchall():
pyodbc.ProgrammingError: No results. Previous SQL was not a query.
Note that if we remove the INSERT statement from the procedure, everything
works like
a charm (except no side effect occurs which is the point of the procedure I'm
trying
to run...)
Running the above procedure from SQL Server Management studio works fine.
Original comment by aurelien...@gmail.com
on 1 Jun 2010 at 4:06
This is a weird SQL Server issue. By default, SQL Server returns rowcounts as
results
for each insert and delete. So in your case, you are getting *two* sets of
results,
(1) the number of rows inserted and (2) the actual rows.
See the discussion of SET NOCOUNT ON at
http://code.google.com/p/pyodbc/wiki/StoredProcedures
Since you own the stored procedure, the easiest thing to do is to add SET
NOCOUNT ON
at the top of it.
Since I'm sure that is what it is, I'll close this, but please reopen if there
is
something else.
Original comment by mkleehammer
on 1 Jun 2010 at 4:37
try at the begin of your procedure:
SET NOCOUNT ON;
SET NOCOUNT ON;
SET NOCOUNT ON;
SET NOCOUNT ON;
SET NOCOUNT ON;
SET NOCOUNT ON;
SET NOCOUNT ON;
Original comment by filosde...@gmail.com
on 3 Mar 2011 at 8:17
Original issue reported on code.google.com by
sankumar...@gmail.com
on 16 Nov 2009 at 7:17