I work with Nhibernate and TransactionScope in a large application. The application must modify 3 databases and support a distributed transaction through them. This is the code that I call every time I want to query or execute some sql in the database as part of a distributed transaction:
IDbConnection connection = new SqlConnection(connectionString);
connection.Open();
ISession session = SessionFactory.OpenSession(connection);
And this is the code called whenever necessary operations are performed
IDbConnection sqlConnection = session.Connection;
if (sqlConnection != null && sqlConnection.State == ConnectionState.Open)
sqlConnection.Close();
session.Dispose();
When I execute update-insert-delete instructions, I also wrap the code inside this:
using (var transaction = session.BeginTransaction())
{
transaction.Commit();}
I think this is pretty standard stuff. Now ... I am doing these operations inside this block:
using (TransactionScope scope = new TransactionScope())
{
scope.Complete();
}
My problem is that my transaction is interrupted sporadically about 6 seconds after it starts (Transaction.Current.TransactionInformation.Status becomes interrupted).
:
pid=6296 ;tid=13300 ;time=04/17/2012-19:34:29.430 ;seq=1 ;eventid=TRANSACTION_MANAGER_STARTED_2 ;;"TM Identifier='(null) '" ;"MS DTC started with the following settings: Security Configuration (OFF = 0 and ON = 1): Network Administration of Transactions = 0, Network Clients = 1, Inbound Transactions = 1, Outbound Transactions = 1, Transaction Internet Protocol (TIP) = 0, XA Transactions = 0, MSDTC RPC Security = Mutual Authentication Required, Account = NT AUTHORITY\NetworkService, Firewall Exclusion = 0, Transaction Bridge Installed = 0, Filtering duplicate events = 1."
pid=6296 ;tid=13300 ;time=04/17/2012-19:34:29.430 ;seq=2 ;eventid=TRACE_SETTINGS ;;"TM Identifier='(null) '" ;"Trace Configuration (OFF = 0 and ON = 1): Tracing Of DTC = 1, Tracing Of Transactions = 1, Tracing Of Aborted Transactions = 1, Tracing Of Long-Lived Transactions = 1, Tracing Of All Transactions = 0, Max Limit on Memory Buffers = 0."
pid=6296 ;tid=11372 ;time=04/17/2012-19:35:19.496 ;seq=3 ;eventid=CHECKPOINTING_STOPPED ;;"TM Identifier='(null) '" ;"MSDTC is suspending the checkpointing of transactions due to lack of activity"
pid=6296 ;tid=11372 ;time=04/17/2012-19:35:19.496 ;seq=4 ;eventid=TRACING_STOPPED ;;"TM Identifier='(null) '" ;"MSDTC is suspending the tracing of long - lived transactions due to lack of activity"
pid=6296 ;tid=10520 ;time=04/17/2012-19:36:31.191 ;seq=5 ;eventid=TRACING_STARTED ;;"TM Identifier='(null) '" ;"MSDTC is resuming the tracing of long - lived transactions"
pid=6296 ;tid=10520 ;time=04/17/2012-19:36:31.212 ;seq=6 ;eventid=TRANSACTION_BEGUN ;tx_guid=5c61419a-eec2-49c1-aaa1-007645a72e32 ;"TM Identifier='(null) '" ;"transaction has begun, description :'user_transaction'"
pid=6296 ;tid=10520 ;time=04/17/2012-19:36:31.212 ;seq=7 ;eventid=RM_ENLISTED_IN_TRANSACTION ;tx_guid=5c61419a-eec2-49c1-aaa1-007645a72e32 ;"TM Identifier='(null) '" ;"resource manager
pid=6296 ;tid=8016 ;time=04/17/2012-19:36:36.141 ;seq=8 ;eventid=RECEIVED_ABORT_REQUEST_FROM_BEGINNER ;tx_guid=5c61419a-eec2-49c1-aaa1-007645a72e32 ;"TM Identifier='(null) '" ;"received request to abort the transaction from beginner"
pid=6296 ;tid=8016 ;time=04/17/2012-19:36:36.141 ;seq=9 ;eventid=TRANSACTION_ABORTING ;tx_guid=5c61419a-eec2-49c1-aaa1-007645a72e32 ;"TM Identifier='(null) '" ;"transaction is aborting"
pid=6296 ;tid=8016 ;time=04/17/2012-19:36:36.141 ;seq=10 ;eventid=RM_ISSUED_ABORT ;tx_guid=5c61419a-eec2-49c1-aaa1-007645a72e32 ;"TM Identifier='(null) '" ;"abort request issued to resource manager
pid=6296 ;tid=8016 ;time=04/17/2012-19:36:36.219 ;seq=11 ;eventid=RM_ACKNOWLEDGED_ABORT ;tx_guid=5c61419a-eec2-49c1-aaa1-007645a72e32 ;"TM Identifier='(null) '" ;"received acknowledgement of abort request from the resource manager
pid=6296 ;tid=8016 ;time=04/17/2012-19:36:36.219 ;seq=12 ;eventid=TRANSACTION_ABORTED ;tx_guid=5c61419a-eec2-49c1-aaa1-007645a72e32 ;"TM Identifier='(null) '" ;"transaction has been aborted"
- , , ?
.
1:
2 2- transactioncope, . , , , :
The PROMOTE TRANSACTION request failed because there is no local transaction active.
.Open(), .