2
I have a method where I save several classes and call another method to do an optimization on top of these classes, but I am using Transaction
, in case something goes wrong in this optimization I need to give rollback
.
Transaction
using (var context = new AppContext())
{
using (var dbContextTransaction = context.Database.BeginTransaction())
{
I tried to change the isolationLevel so:
using (var dbContextTransaction =
context.Database.BeginTransaction(IisolationLevel.snapshot))
Yet he still gives lock
at the bank, I wonder why this happens and how I would get around this situation, basically I would like to do a Optimistic concurrency control
, without checking at commit time, simply the last version is saved.
Obs. using some commands directly in the database I get the experienced behavior, but it seems to me that the isolationLevel that I Seto in Begintransaction is not serving at all, in case someone can explain to me the functioning and clarify me what I am missing, I will be grateful.
Commands used:
ALTER DATABASE [DB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE [DB] SET READ_COMMITTED_SNAPSHOT ON;
ALTER DATABASE [DB] SET ALLOW_SNAPSHOT_ISOLATION ON;
ALTER DATABASE [DB] SET MULTI_USER
Which bank?
– novic
Sorry, it’s SQL SERVER
– William Cézar
I don’t see any magic possible... when you set the database to Single_user, independent of transaction, until it reaches Multi_user, the database will not accept new connections
– Leandro Angelo