SystemError: <class 'pyodbc.Error'> returned a result with an error set

Question:

def insert(self):
    conn = pyodbc.connect(
        'Driver={SQL Server};'
        'Server=DESKTOP-S0VG212SQLEXPRESS;'
        'Database=MovieGuide;'
        'Trusted_Connection=yes;'
    )
    cursor = conn.cursor()

Error occurs when executing the query but I don’t know what’s causing it.

cursor.execute('insert into Movies(MovieName,Genre,Rating,Username) values(?,?,?,?);',
               (self.moviename, self.moviegenre, self.ratebox, self.username))
conn.commit()
Asked By: Abubakar Soomro

||

Answers:

I know my answer is late, but it can be useful to someone.

SystemError: <class 'pyodbc.Error'> returned a result with an error set error appears when the query is wrong, make sure you are executing the correct query using SQL server query window then you can able to identify the problem.

In the question, the semicolon should not come to the end of the query, if you still get an error, it might chances for the column to have some constraint issue. So follow the below method when you are facing this issue.

Execute one insert query in the SQL server query tab and identify the
problem.

Answered By: Sathiamoorthy

Using SQL Server with an Openquery to an Oracle Server I got this error because I had a comment in my Oracle SQL.

SET NOCOUNT ON;
If(OBJECT_ID('tempdb..#Temp_OracelTable') Is Not Null)
Begin
    Drop Table #Temp_OracleTable
    End


SELECT *
    INTO #Temp_OracleTable
    FROM    OPENQUERY (OracelConnectionNameOnSQLServer, '
Select Column -- Comment I had to remove
From TableName')
Select * From #Temp_OracleTable
Drop table #Temp_OracleTable
Answered By: Mattman85208

If you’re having this problem with Apache Airflow, you should look for 2 possibles causes:

  • If you’re calling your function inside the file, Airflow doesn’t deal with it.

  • If your query string is correct with you default encoding.

Answered By: lucaspompeun
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.