is this also the case for MySQL 5.x?
i.e. aren't lightweight transactions supported by MySQL?
or is SQLServer the only database which supports .NET 2.0 TransactionScope
In the following test code (using an entity called a Tutor), i intentionally comment out the ts.Complete() calls to try and make the whole transaction fail. The first (main test) method creates a new transaction (RequiresNew), the other methods should use the existing transaction (Required) from the first method.
The results of my test are:
1) the first edit (Tutor.Ssn) remains committedd in the DB
2) the second (Tutor.DateAdded) throws an exception
3) The exception is not thrown where it should be (see bold comments in code below)
The first edit should get rolled back at the missing Complete() call where the using block goes out of scope, no?
Thanks for your help,
KB
[Test]
public void TestTutorEditTransactional()
{
try
{
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
{
using (DataAccessAdapter adapter = MockDataAdapter.GetAdapter())
{
this.theTutor = new MockTutor("Trans", "Dude", "Action", "123-12-1234", "M", 0); //new TutorsEntity();
this.theTutor.TutorEntity.Tid = 7;
if (this.theTutor.Exists())
{
this.EditSsn("123-12-4444");
this.EditDateAdded(DateTime.Today.AddDays(3));
}
}
ts.Complete(); // commit transaction
}
}
catch (Exception ormException)
{
Trace.Write(ormException.ToString());
}
}
public void EditSsn(string testValue)
{
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
{
using (DataAccessAdapter adapter = MockDataAdapter.GetAdapter())
{
PredicateExpression filter = new PredicateExpression();
this.theTutor.TutorEntity.Ssn = testValue;
adapter.SaveEntity(theTutor.TutorEntity, true, filter);
}
//ts.Complete(); // each sub-transaction must complete or root transaction will fail
}
** // ^^ missing ts.Complete() call should immediately throw exception here **
}
public void EditDateAdded(DateTime testValue)
{
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
** // ^^ exception thrown on next use of ts, instead of above at missing ts.Complete()**
{
using (DataAccessAdapter adapter = MockDataAdapter.GetAdapter())
{
PredicateExpression filter = new PredicateExpression();
this.theTutor.TutorEntity.Dateadded = testValue;
adapter.SaveEntity(theTutor.TutorEntity, true, filter);
}
//ts.Complete(); // each sub-transaction must complete or root transaction will fail
}
}