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!

Written by

Data scientist learning and writing about everything.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store