2
我出現以下情況例外,當我運行在行異常中的TransactionScope
EntityScope<TQFormContext>.CurrentObjectContext.SaveChanges();
下面的代碼「與當前連接關聯的事務已完成,但還沒有被釋放。該交易必須在連接前佈置可以用來執行SQL語句。「
[TestMethod()]
public void TransactionTest()
{
using (TransactionScope tc = new TransactionScope())
{
var u1 = EntityScope<TQFormContext>.CurrentObjectContext.ASUsers.FirstOrDefault(u => u.UserID == 1);
var u2 = PersistenceManager.GetById<TQ.Business.PO.Administration.UserPO>(2);
u1.MiddleInitial = "1";
u2.MiddleInitial = "1";
using (SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
SqlCommand sqlComm = new SqlCommand("Update asusers set middleinitial='1' where userid=3", sqlConn);
sqlConn.Open();
sqlComm.ExecuteNonQuery();
}
PersistenceManager.SaveOrUpdate(u2);
EntityScope<TQFormContext>.CurrentObjectContext.SaveChanges();
// throw new Exception("Blah");
tc.Complete();
}
}