The SQL server executes the task and prompts "Generation failed, data exception. Reason The transaction count after EXECUTE indicates that the number of BEGIN and COMMIT statements does not match. Previous count = 1, current count = 0."

This is an SQL exception indicating that the transaction count after EXECUTE indicates a mismatch in the number of BEGIN and COMMIT statements.

According to the prompt, you can see that the previous count is 1 and the current count is 0. This means that there is an unclosed transaction in the previous operation or an exception occurs during transaction processing, resulting in the failure of subsequent transactions to be processed normally.

The solution to this problem is: first, ensure that the number of BEGIN and COMMIT statements in the transaction is equal, that is, each BEGIN statement must have a corresponding COMMIT statement to close the transaction. Secondly, it is necessary to check whether there is an exception in the previous transaction, and if there is an exception, it needs to be rolled back.

The specific operation steps are as follows:

  1. Check whether there is a mismatch between BEGIN and COMMIT during code execution, and confirm whether the number of statements matches.

  2. Check whether there is an exception in the previous code, and if there is an exception, it needs to be rolled back.

  3. Execute the ROLLBACK command to roll back to the state before the exception to clear unfinished transactions and ensure that the transaction environment is in a normal state.

  4. Manually execute the COMMIT command to submit subsequent transaction operations to avoid repeated occurrences of this problem during operations.

It should be noted that this exception may be caused by various reasons, so if the above methods cannot solve the problem, further investigation is required.

If the above methods do not solve the problem, you can also try the following methods:

  1. Check whether the program is multi-threaded or concurrently executed, and ensure that thread access operations in a transactional environment are thread-safe.

  2. Check whether the database connection is normal, and whether the database version used supports the current SQL operation.

  3. Diagnose the database to see if there are problems such as locks or deadlocks in the database, and try to re-execute the SQL statement after eliminating these problems.

  4. By adding debugging output, you can gradually troubleshoot problems in SQL statements, such as syntax errors and illegal parameters.

Guess you like

Origin blog.csdn.net/qq1507171150/article/details/130980932