TransactionScope not working with a simple use case -bug?
Posted: Fri 23 Oct 2009 17:50
I have a very simple use case that is not working and I believe that it should. Either I am understanding something fundamentally wrong with TransactionScope (I have followed all the examples exactly) or this is a bug.
My model is a simple person table with one column FIRSTNAME. Below are two methods - one that using a Required TransactionScope and one that uses no TransactionScope. I can call each method by itself repeatedly, but as soon as I call the Required one and then call the No Transaction one I get an error
Devart.Data.Oracle.an.b(int A_0 = -1)
Devart.Data.Oracle.at.c(int A_0 = -1)
Devart.Data.Oracle.at.a(bool A_0 = false)
Devart.Data.Oracle.OracleInternalConnection.Commit()
Devart.Data.Oracle.OracleTransaction.Commit()
System.Data.EntityClient.EntityTransaction.Commit()
System.Data.Objects.ObjectContext.SaveChanges(System.Data.Objects.SaveOptions options = {unknown})
I only added the call to explicitly open and close the connection when I saw a forum post about this possibly helping - the behavior of the code is the same without the explicit connection open/close.
Any help/explanation would be appreciated
Bryan
________
My model is a simple person table with one column FIRSTNAME. Below are two methods - one that using a Required TransactionScope and one that uses no TransactionScope. I can call each method by itself repeatedly, but as soon as I call the Required one and then call the No Transaction one I get an error
when trying to call SaveChanges in the DoNoTransaction. The Stack trace is thisORA-24776: cannot start a new transaction
Devart.Data.Oracle.an.b(int A_0 = -1)
Devart.Data.Oracle.at.c(int A_0 = -1)
Devart.Data.Oracle.at.a(bool A_0 = false)
Devart.Data.Oracle.OracleInternalConnection.Commit()
Devart.Data.Oracle.OracleTransaction.Commit()
System.Data.EntityClient.EntityTransaction.Commit()
System.Data.Objects.ObjectContext.SaveChanges(System.Data.Objects.SaveOptions options = {unknown})
Code: Select all
public void DoRequiredScope()
{
try
{
TransactionOptions transOptions = new TransactionOptions();
transOptions.IsolationLevel = IsolationLevel.ReadCommitted;
transOptions.Timeout = new TimeSpan(0, 0, 30);
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, transOptions))
{
Debug.WriteLine("Current Transaction is " + Transaction.Current.TransactionInformation.LocalIdentifier);
Transaction.Current.TransactionCompleted += Current_TransactionCompleted;
using (Entities entities = new Entities())
{
entities.Connection.Open();
PERSON app = entities.PERSON.First();
app.FIRSTNAME = "A Change w/txn";
Console.WriteLine(app.FIRSTNAME);
entities.SaveChanges();
entities.Connection.Close();
}
ts.Complete();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
//throw;
}
}
public void DoNoTransaction()
{
try
{
using (Entities entities = new Entities())
{
entities.Connection.Open();
PERSON app = entities.PERSON.First();
app.FIRSTNAME = "A Change w/o txn";
Console.WriteLine(app.FIRSTNAME);
entities.SaveChanges();
entities.Connection.Close();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
}
Any help/explanation would be appreciated
Bryan
________