Reputation: 16423
There are many solutions on the web for using Entity Framework and getting this error:
Execution strategy 'SqlServerRetryingExecutionStrategy' does not support user-initiated transactions
I ran into this issue and followed the recommended fixes on the internet and I no longer have the problem in that one sql transaction I was doing. The problem is, I need to find other areas of my app that could cause the same issue and fix them. How can I do this when I don't know what a "User initiated transaction" is. I've looked all over the web including Microsoft's knowlege article on this issue HERE but they don't define this term.
I "think" it is when you are using a transaction scope
, or a using BeginTransaction()
but I would rather not guess.
Can someone define this term please?
Upvotes: 0
Views: 173
Reputation: 29840
A user initiated transaction is a database transaction you or some code started using a SqlTransaction
. For example:
using (SqlConnection objConn = new SqlConnection(strConnString))
{
objConn.Open();
objTrans = objConn.BeginTransaction();
SqlCommand objCmd1 = new SqlCommand("insert into tblProject values(1, 'TestProject')", objConn);
SqlCommand objCmd2 = new SqlCommand("insert into tblProjectMember(MemberID, ProjectID) values(2, 1)", objConn);
try
{
objCmd1.ExecuteNonQuery();
objCmd2.ExecuteNonQuery(); // Throws exception due to foreign key constraint
objTrans.Commit();
}
catch (Exception)
{
objTrans.Rollback();
}
finally
{
objConn.Close();
}
}
Upvotes: 1