.Net Framework 4.5. Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction -


i´m working on distributed transaction issue occurs using net framework 4.5. if try execute app on machine (and dev server also) using framework 4.0 components work fine. problem started when installed fwk4.5 on machine , run on. installed framework, never changed source code neither changed target framework on assemblies.

i need know why happening, if behavior of entity framework , distributed transactions have been changed after fwk4.0.

i read lot couldn´t figure out yet. apreciated.

best regards, diego

here can see simple code sample reproduce error:

note: notice if objectcontext connection not opened manually before transaction works fine.

   public static bool dotran_objectcontext()         {             string strc = configurationmanager.connectionstrings["testdb2entities"].connectionstring; //"metadata=res://*/testdb2model.csdl|res://*/testdb2model.ssdl|res://*/testdb2model.msl;provider=system.data.sqlclient;provider connection string="data source=.\sqlexpress;initial catalog=testdb2;integrated security=true;pooling=false;multipleactiveresultsets=true;application name=entityframework""             objectcontext oc = new objectcontext(strc);              //this line causes enlist error @ end of function/////             oc.connection.open();             ///////////////////////////////////////////////              var t = (from s in oc.createobjectset() s.id == 2 select s).firstordefault();              t.valor = "cambiado_" + datetime.now;              using (transactionscope scope2 = new transactionscope(transactionscopeoption.required, new transactionoptions() { isolationlevel = system.transactions.isolationlevel.readcommitted }))             {                  string cstr = configurationmanager.connectionstrings["defaultconnection"].connectionstring; //"data source=.\\sqlexpress;initial catalog=testdb2;integrated security=true";                 system.data.sqlclient.sqlconnection conn = new system.data.sqlclient.sqlconnection(cstr);                 conn.open();                 sqlcommand cmd = conn.createcommand();                 cmd.commandtype = commandtype.text;                 cmd.commandtext = "insert tabla1_db2 values('" + datetime.now.tostring() + "')";                  sqltransaction tran = conn.begintransaction(system.data.isolationlevel.readcommitted);                 cmd.transaction = tran;                 cmd.executenonquery();                  tran.commit();                 conn.close();                  oc.savechanges();                  scope2.complete();             }              //on line error thrown             var t2 = (from s in oc.createobjectset() s.id == 2 select s).firstordefault();              return true;         }  

error:

 "distributed transaction completed. either enlist session in new transaction or null transaction." 

thanks!

i think problem related isolationlevel being different in 1 of scopes stated here

when using nested transactionscope objects, nested scopes must configured use same isolation level if want join ambient transaction. if nested transactionscope object tries join ambient transaction yet specifies different isolation level, argumentexception thrown.

by default isolation level serializable, you're setting transaction readcommitted, if caller runs serializable transaction you're involved in it.


Comments