Handle transaction when invoking SQL stored procedure in side a C# loop -
i'm working on system developed other developers. , in system have invoked stored procedure use insert records in side loop in c# without using user define table types.
and need add transaction scenario. problem have no idea place have transaction.
i know whether have in c# code warping loop or inside stored procedure.
you can have inside c# loop. transaction started inside procedure must commit before procedures exits. sql server checks @@trancount
before , after running procedure , if results don't match exception raised. impossible procedure start transaction has committed caller.
the easiest think wrap c# code in transaction scope:
using(var scope = new transactionscope( transactionscopeoption.required, new transactionoptions() { isolationlevel = isolationlevel.readcommitted })) { // work here scope.complete(); }
note passing isolationlevel = isolationlevel.readcommitted
critical.
Comments
Post a Comment