| Issue 243: | Exception "No results. Previous SQL was not a query." when stored SQL 2000 proc uses print statement | |
| 1 person starred this issue and may be notified of changes. | Back to list |
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!
Mar 5, 2012
Project Member
#1
mkleehammer
Status:
Complete
Mar 5, 2012
Ah, cool! Thanks! I'll try it out.
Jun 7, 2012
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?
Dec 20, 2013
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. |