The COMMIT TRANSACTION request has no corresponding BEGIN


Error thrown when inserting data into SQL Server database using Python:

Cannot commit transaction: (3902,b'The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
DB-Lib error message 20018, severity 16:\nGeneral SQL Server error:Check messages from the SQL Server\n')


Well, there’s no reason. But a solution was found by accident.


The error caused by the field type in sqlserver. The error I encountered is: one of the fields is set to date type. When inserting data, I report an error. Change the date type to varchar type, the problem is solved, and the data is inserted normally.


The varchar type may affect the data usage. Solve the problem first, and then solve the problem later. I think that inserting varchar data into the database is the most stable (personal experience).

Personal ability is limited, if there is a mistake welcome to correct!

Read More: