简体   繁体   中英

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()

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.

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

class 'pyodbc.error' returned a result with an error set

pyodbc error “SystemError: <class 'pyodbc.Error'> returned a result with an error set” . see your connection my issue is be system error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM