Home > OS >  If I have autocommit=True for pyodbc connection, can I assume I don't have to do cursor commits
If I have autocommit=True for pyodbc connection, can I assume I don't have to do cursor commits

Time:12-16

I have the example code below. Do I still need a cursor commit after the last line? I am running against a SQL server 2016 DB host if that matters.

import pyodbc
cnxn = pyodbc.connect('Driver=SQL Server;Server=localhost;Database=mydb;Trusted_Connection=yes;')
cnxn.autocommit = True
cursor = cnxn.cursor()
cursor.execute('update mytable set myfield=1')

CodePudding user response:

No, you don't need to do the cursor.commit()

cnxn.autocommit = True

This line in your code will commit all your transactions to the SQL

  • Related