(I know the circumstances surrounding the DTC and promoting a transaction can be a bit mysterious to those of us not in the know, but let me show you how my company is doing things, and if you can tell me why the DTC is getting involved, and if possible, what I can do to avoid it, I'd be grateful.)
I have code running on an ASP.Net webserver. We have one database, SQL 2008.
Our data access code looks something like this-- We have a data access layer that uses a wrapper object for SQLConnections and SQLCommands. Typical use looks like this:
void method1()
{
objDataObject = new DataAccessLayer();
objDataObject.Connection = SomeConnectionMethod();
SqlCommand objCommand = DataAccessUtils.CreateCommand(SomeStoredProc);
//create some SqlParameters, add them to the objCommand, etc....
objDataObject.BeginTransaction(IsolationLevel.ReadCommitted);
objDataObject.ExecuteNonQuery(objCommand);
objDataObject.CommitTransaction();
objDataObject.CloseConnection();
}
So indeed, a very thin wrapper around SqlClient, SqlConnection etc. I want to run several stored procs in a transaction, and the wrapper class doesn't allow me access to the SqlTransaction so I can't pass it from one component to the next. This led me to use a TransactionScope:
using (TransactionScope tx1 = new TransactionScope(TransactionScope.RequiresNew))
{
method1();
method2();
method3();
tx1.Complete();
}
When I do this, the DTC gets involved, and unfortunately our webservers don't have "allow remote clients" enabled in the MSDTC settings-- getting IT to allow that will be a fight.
I'd love to avoid DTC becoming involved but can I do it? Can I leave out the transactional calls in methods1-3() and just let the TransactionScope figure it all out?