The DalManager (and the ConnectionManager) relies on reference counting to determine when close the actual connection.
The rules are not making sure to dispose the DalManager and hence the DalManager and reference counting is off. Resulting in the update happening on a connection that was created and opened in one of the Fetch operations and is therefore not be enlisted in the TransactionScope on the Update method.
See: http://msdn.microsoft.com/en-us/library/bb896149%28v=sql.100%29.aspx
All rules must be changed to dispose of the DalManager. Original rule:
protected override void Execute(RuleContext context)
{
var name = (string)context.InputPropertyValues[_nameProperty];
var id = (int)context.InputPropertyValues[_idProperty];
var dal = DalFactory.GetManager();
var countryDal = dal.GetProvider<ICountryDal>();
var exists = countryDal.Exists(id, name);
if (exists)
{
context.AddErrorResult("Country with the same name already exists in the database.");
}
}
DalManager is IDisposable but is not explicitly disposed here so it depends on when the GC will actually collect the object.
Should be:
protected override void Execute(RuleContext context)
{
var name = (string)context.InputPropertyValues[_nameProperty];
var id = (int)context.InputPropertyValues[_idProperty];
using (var dal = DalFactory.GetManager())
{
var countryDal = dal.GetProvider<ICountryDal>();
var exists = countryDal.Exists(id, name);
if (exists)
{
context.AddErrorResult("Country with the same name already exists in the database.");
}
}
}