Added functionality to restore auto-commit state if commit fails.