小编Ama*_*mar的帖子

使用TransactionScope()进行事务管理

我需要创建一个简单的dotnet应用程序,它将在循环内调用存储过程(存储过程接受几个参数并将它们添加到表中).要求是所有行都插入或非插入.

为了确保这一点,我使用过:

using (TransactionScope scope = new TransactionScope())
{
    foreach (EditedRule editedRules in request.EditedRules)
    {
            ...stored procedure call
    }
}
Run Code Online (Sandbox Code Playgroud)

我以前从未使用TransactionScope过,有人可以告诉我这段代码是否有效,并且我的所有行都会被回滚.

如果有更好的方法,我也将不胜感激.

.net c# sql-server asp.net

3
推荐指数
1
解决办法
753
查看次数

标签 统计

.net ×1

asp.net ×1

c# ×1

sql-server ×1