我正在寻找一个大型业务应用程序中的一个错误,该错误中的业务流程失败了,但是部分持久化到了数据库中。为了使问题更难弄清,该过程每隔几周就会失败一次,每次失败之间都会成功处理数十万次。当并发性/工作进程数增加时,错误频率似乎会增加。
到目前为止,我们已经能够重新创建该程序所看到的内容。(.NET 4.7.1框架)
using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
using (var sqlConnection = new SqlConnection("Server=localhost;Database=Database1;Trusted_Connection=True"))
{
sqlConnection.Open();
// Doing some unwanted nested manual transaction and rolling it back
var transaction = sqlConnection.BeginTransaction();
new SqlCommand($"INSERT INTO TestTable VALUES('This will be rolled back}')", sqlConnection).ExecuteNonQuery();
transaction.Rollback();
// Now doing some work with the DB.
// You might expect it to become a part of transactionScope, but that is NOT the case!
// So this command will actually succeed, with data written to …Run Code Online (Sandbox Code Playgroud)