execution strategy 'SqlServerRetryingExecutionStrategy' does not support user initiated transactions. Use the execution strategy returned
Hello the Full Error says like this:
The configured execution strategy 'SqlServerRetryingExecutionStrategy' does not support user initiated transactions. Use the execution strategy returned by 'DbContext.Database.CreateExecutionStrategy()' to execute all the operations in the transaction as a retriable unit.
Here is the Code I use Execution Strategy Twice inside one Function: This is on the top
using(var posDbCtx = new PosDbContext())
{
var strategy = posDbCtx.Database.CreateExecutionStrategy();
strategy.Execute(
() =>
{
using (var transaction = posDbCtx.Database.BeginTransaction())
{
_posDbContext.PrintJobs.Add(_printJobs);
_posDbContext.SaveChanges();
transaction.Commit();
}
});
}
this is after code:
using (var posDbCtx = new PosDbContext())
{
var strategy = posDbCtx.Database.CreateExecutionStrategy();
strategy.Execute(
() =>
{
using (var transaction = posDbCtx.Database.BeginTransaction())
{
int lineindex = 0;
foreach (var jline in _printjoblines)
{
var pjobline = new PrintJobLine();
pjobline.PrintLineId = Guid.NewGuid();
pjobline.PrintJobId = jline.PrintJobId;
pjobline.LineIndex = lineindex;
pjobline.Text = jline.Text;
pjobline.RightText = jline.RightText;
pjobline.LeftText = jline.LeftText;
pjobline.LineLength = jline.LineLength;
pjobline.PrintOptions = jline.PrintOptions;
pjobline.ItemName = jline.ItemName;
pjobline.Quantity = jline.Quantity;
pjobline.Flags = jline.Flags;
pjobline.BergPlu = jline.BergPlu;
pjobline.ActualPrice = jline.ActualPrice;
pjobline.BasePrice = jline.BasePrice;
pjobline.Vducolor = jline.Vducolor;
pjobline.ParentIndex = jline.ParentIndex;
pjobline.Peplu = jline.Peplu;
pjobline.SaleItemId = jline.SaleItemId;
pjobline.SaleTenderId = jline.SaleTenderId;
pjobline.SignatureId = jline.SignatureId;
//pjobline.Language = 0;
_posDbContext.PrintJobLines.Add(pjobline);
_posDbContext.SaveChanges();
lineindex++;
}
transaction.Commit();
}
});
}
my explanation upon doing this on my local im using SQL Server 2019 Latest Version 15.0.18386.0 and the database version on which i'd deployed it is SQL Server 2014 Version 12.0.6164.21
i think due to the version the reason why it gives this error is there another for the codes above be revised for the old version SQL Server 2014 to be able to run it without the error?