I want to say thank you to all who had replied, and I want to give you some update, it may helps someone who has same my issue. I have added try: and except and this was solving my problem:
try: cnn.autocommit = False cursor.execute("""INSERT INTO (A) values (?)""",AA) except pyodbc.DatabaseError as err: print(err) cnn.rollback() else: cnn.commit() finally: cnn.autocommit = True cnn.commit() cnn.close()