对于确实具有平衡事务块的存储过程,您是否遇到过此异常?
我仔细检查了存储过程,它正好有一个TRANSACTION BEGIN
和相应的TRANSACTION END
记录错误
SqlException - Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0. The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION. - Delete failed - stack: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.S ... [Rest of stack trace truncated by logging system]`
附加信息
存储过程确实包含EXEC
对另一个存储过程的调用。这里的不匹配交易对会导致错误以这种方式浮出水面吗?
更新
事实证明嵌套存储过程中存在外键约束违规。外部事务不包含 Try/Catch 块并且已SET XACT_ABORT ON
指定,它没有正确处理提交或回滚。在尝试回滚之前还添加了对 @@TransactionCount > 0 的检查