GoogleCodeArchives / pyodbc

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

Exception "No results. Previous SQL was not a query." when stored SQL 2000 proc uses print statement #243

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a SQL 2000 stored procedure:
CREATE PROCEDURE p_ConfusePyodbc AS
print 'hello world'
SELECT 1 AS Data
GO

2. Execute the procedure with pydobc and access the records in the cursor.
import pyodbc
conn = pyodbc.connect("<<connection string>>")
cursor = conn.cursor()
cursor.execute("exec p_ConfusePyodbc")
print cursor.fetchone()

3. If the 'hello world' print statement executes, pyodbc throws the exception 
"No results. Previous SQL was not a query." is thrown.

3a. Removing the print statement from the proc makes the problem go away.

The expected output is a recordset. Instead, I see an exception.

What version of the product are you using? On what operating system?
3.0.3 on Python 2.7.

Please provide any additional information below.
We use print statements in SQL 2000 all the time for debugging purposes. Having 
a developer who doesn't know anything about pyodbc add a print statement, and 
thereby take down any app that uses pydbc is pretty dangerous!

Original issue reported on code.google.com by gol...@gmail.com on 5 Mar 2012 at 11:53

GoogleCodeExporter commented 9 years ago
This was fixed in 3.0.5, which I don't have many installers for.  I do have one 
for 32-bit Windows Python 2.7, however, which it looks like you are using.  
Thanks.

Original comment by mkleehammer on 5 Mar 2012 at 11:55

GoogleCodeExporter commented 9 years ago
Ah, cool! Thanks! I'll try it out.

Original comment by gol...@gmail.com on 6 Mar 2012 at 12:15

GoogleCodeExporter commented 9 years ago
Using 3.0.5 (pyodbc-3.0.5-py2.7-win32.egg), I still see the same issue. I call 
a stored procedure that sends out results using print statements, but a call to 
fetchal() or fetchone() fails. The nextset() function returns True if I call it 
9 times, which corresponds to the number of lines of output, but I cannot get 
to the output itself. Any thoughts?

Original comment by james.qu...@gmail.com on 7 Jun 2012 at 8:29

GoogleCodeExporter commented 9 years ago
Using the solution from 
http://stackoverflow.com/questions/7753830/mssql2008-pyodbc-previous-sql-was-not
-a-query worked for me. Issue "SET NOCOUNT ON;" before your exec statement. 
This should really be fixed by the library, but as a workaround it suffices.

Original comment by joshseg...@google.com on 20 Dec 2013 at 2:59