I got a serviced component which looks something like this (not written by me):
[Transaction(TransactionOption.Required, Isolation = TransactionIsolationLevel.Serializable, Timeout = 120), EventTrackingEnabled(true)]
public class SomeComponent : ServicedComponent
{
public void DoSomething()
{
try
{
//some db operation
}
catch (Exception err)
{
ContextUtil.SetAbort();
throw;
}
}
Is the ContextUtil.SetAbort() really required? Won’t the exception abort the transaction when the component is left?
Only if you want to manage the transaction manually.
Your component will vote automatically to abort (in case any exception is raised), or commit, if you decorate your operation with the
[AutoComplete]attribute in this way:EDIT:
For more info about this attribute, see MSDN here:
Anyway if you are (in the rare case) that really need to manage the transaction manually, is really important that you don’t leave your transactions in doubt. I’m missing in your code the
ContextUtil.SetComplete();that should be explicitly called.