We can close the connection by deleting the connection object, del cnxn in this case. Otherwise the connection will close either on exception or code completion.

Additionally, cursor.commit() commits the active transaction.

Using both of these together should be sufficient, or at least it has been in my experience.

It’s a very good question, and I think I may go and read a little more on this soon, thanks for bringing it up!

Freelance ML engineer learning and writing about everything.

Freelance ML engineer learning and writing about everything.