ERROR: No results. Previous SQL was not a query.

See original GitHub issue

Environment

To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:

  • Python: 3.9
  • pyodbc: 4.0.26
  • OS: <AWS Lambda environment>
  • DB: SQL Server
  • driver: ODBC Driver 17 for SQL Server

Issue

We have multiple users in the SQL database and we want to reset the password for some users by using master user login, but when we try to reset the password using the lambda function, it is showing the error as “ERROR: No results. The previous SQL was not a query.” but other SQL statements(Select or Insert) are working as expected rather “ALTER

Here is a code sample:

import json
import pyodbc

def lambda_handler(event, context):
    try:
        pyodbc.pooling = False
        conn = pyodbc.connect('Driver={ODBC Driver 17 for SQL Server};Server=amazon-rd-endpoint,1433;Database=database_name;Uid=supper_user;Pwd=password;CENSORED;Trusted_Connection=yes;',autocommit=True)
        cursor = conn.cursor()
        
        cursor.execute("ALTER LOGIN second_user WITH PASSWORD = 'newPassword'")
        conn.commit()

        return {
            'statusCode': 200,
        }
    except Exception as e:
        print('ERROR: ', e)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
v-chojascommented, Sep 1, 2021

The error comes from line 100 here:

https://github.com/mkleehammer/pyodbc/blob/24e0ccadaec091ce6b1b81e3197a345b895773fc/src/cursor.cpp

…so Cursor_Validate needs to be called with at least CURSOR_REQUIRE_RESULTS and CURSOR_RAISE_ERROR for that to occur. Where does that happen?

  • Cursor_iternext
  • Cursor_fetchval
  • Cursor_fetchone
  • Cursor_fetchall
  • Cursor_fetchmany
  • Cursor_skip

…none of which are called from Cursor_execute, so the error you are getting in this issue is practically impossible given the code you claim to be executing.

1reaction
v-chojascommented, Aug 30, 2021

I am not sure what you are trying to say. In any case, neither me nor Gord are able to reproduce your issue. What did you expect? The previous SQL was indeed not a query.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MSSQL2008 - Pyodbc - Previous SQL was not a query
I have solved this problem by splitting the use database and sql query into two execute statements.
Read more >
pyodbc.ProgrammingError: No results. Previous SQL ... - Reddit
I've created a non standard query with temp tables and drop requests. The query bundle works find in SQL Studio, but I receive...
Read more >
Valid SQL returns error "No results. Previous SQL was not a ...
With the default setting of NOCOUNT OFF, fetchall raises an error. But with NOCOUNT ON, the query is successful. Output: without SET NOCOUNT...
Read more >
Error "Previous SQL was not a query" in Python?-sql-server
I got the error: "ProgrammingError: No results. Previous SQL was not a query." on some SQL with an openquery (not a Stored Procedure)....
Read more >
No results when using known good SQL code - Google Groups
MS-SQL code (to the same database/server via pyobdc): pyodbc.ProgrammingError: No results. Previous SQL was not a query. The proven code (in the “SQL_COMMANDS" ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found