1
I’m thinking of implementing TransactionScope
in my code, however, all bank access is made by StoredProcedures
.
The TransactionScope
can give rollback
in multiple actions carried out in StoredProcedures
?
using (var trans = new TransactionScope()) {
try {
this.Teste1Repository.Insert(); // Chamada a primeira PROC
this.Teste2Repository.Insert(); // Chamada a segunda PROC
trans.Complete();
}
catch {
// Trata erro
}
}
NOTE: If you want to continue using the Procedures, you will have to implement Rollback on your own. Here is an example in SQL: https://stackoverflow.com/a/13171451/6579651
– Renan Valentim
In this case, procs do not have transactions. Therefore, the Transactionscope rollback would work, correct?
– Claudio Neto
It wouldn’t work, because what matters in this case is Commit, since SP1 has already executed its entire function, gave a commit, went back to C# and ran SP2. In this case you would have to join the 2 Procedures in 1 only, and do the Rollback treatment within the same.
– Renan Valentim
Even without the code starting a transaction and committing? Because my procs do not have transaction/commit/rollback.
– Claudio Neto
@Claudioneto I don’t understand what your difficulty is. I answered your question just above, what is going wrong there?
– Renan Valentim