Skip to content
Advertisement

Function sequence error in PYODBC

I am using pyodbc to connect to a database and extract certain data from it.

Here is my code:

JavaScript

And I got following error after I run above code:

pyodbc.Error: (‘HY010’, ‘[HY010] [Microsoft][ODBC SQL Server Driver]Function sequence error (0) (SQLFetch)’)

May I know what caused such problem, and how can I fix it?

Thanks.

Advertisement

Answer

I believe your problem is the strange commit statements. You only need to commit when inserting or updating records not selecting.

JavaScript

Also, in the future when using commit, both cursor.commit and con.commit do the same thing, you only need one.

Finally, I’d get used to calling execute with the second arguement as a tuple:

JavaScript

The way you have it works for pyodbc but is not DB API standard.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement