Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

def insert(self):
    conn = pyodbc.connect(
        'Driver={SQL Server};'
        'Server=DESKTOP-S0VG212\SQLEXPRESS;'
        '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()
like image 225
Abubakar Soomro Avatar asked Jan 02 '20 12:01

Abubakar Soomro


1 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.

like image 159
Sathia Avatar answered Sep 18 '22 03:09

Sathia