中文字幕精品亚洲无线码二区,国产黄a三级三级三级看三级,亚洲七七久久桃花影院,丰满少妇被猛烈进入,国产小视频在线观看网站

將不確(que)定變(bian)為(wei)確(que)定~transactionscope何時提升為(wei)分(fen)布式事務~續(xu)

回到目錄

相關文章

將不確定變為確定~transactionscope何時提升為分布式事務

將不確定變為確定~transactionscope何時提升為分布式事務~續      

將不確定變為確定~transactionscope何時提升為分布式事務~再續(避免引起不必要的MSDTC)


 

          之前寫過一篇關于《將不確定變為確定~transactionscope何時提升為分布式事務》的文(wen)章(zhang),但今天又測試了一(yi)下(xia),發現(xian)前一(yi)篇文(wen)章(zhang)有很多問題,這(zhe)里再把問題說一(yi)下(xia)。

一 什么時間會把你的transactionscope提(ti)升為分布式事務,即(ji)要使用MSDTC服務

  1.   當你的WEB服務器與數據庫服務器在同臺電腦上,對同一個庫進行操作時,它不會提升為分布式事務
  2.   當你的WEB服務器與數據庫服務器在同臺電腦上,對于同一個庫,建立多個數據上下文時,它不會提升為分布式事務
  3.   當你的WEB服務器與數據庫服務器在同臺電腦上,當你操作兩個庫的表,這時才會提升為分布式事
  4.       當你的WEB服務器與數據庫服務器不在同臺電腦上,每次都會引發MSDTC

二 案例分析:

 public class DbBase : Commons.Data.DbContextRepositoryBase
    {

        public DbBase()
            : base(Commons.Data.DbFactory.Intance(System.Configuration.ConfigurationManager.ConnectionStrings["testEntities1"].ToString(), 2, 0))
        {

        }
    }

    public class DbBase2 : Commons.Data.DbContextRepositoryBase
    {

        public DbBase2()
            : base(Commons.Data.DbFactory.Intance(System.Configuration.ConfigurationManager.ConnectionStrings["testEntities2"].ToString(), 2, 1))
        {

        }
    }
public class ReviewRepository : DbBase
    {

    }
    public class TestRepository : DbBase
    {
        public void Insert()
        {
            var product = new Product
            {
                Info = "test",
                Name = "test",
            };

            var product_Comment = new Product_Comment
            {
                CommentInfo = "test",
                CommentTitle = "Test",
                ProductID = 1,
                UserID = 1
            };
            var review = new Review
            {
                CreateDate = DateTime.Now,
                Info = "test",
                ObjID = 1,
                ObjType = 1,
                Status = 100,
                UserID = 1,
            };
            using (var trans = new TransactionScope())
            {
                //var testEntities = new testEntities();
                // var testEntities2 = new testEntities();
                #region  一個dbcontext對象不發生MSDTC
                //testEntities.Product.AddObject(product);
                //testEntities.Review.AddObject(review);
                //testEntities.SaveChanges();
                #endregion

                #region  多個dbcontext對象也不發生MSDTC
                //testEntities.Product.Add(product);
                //testEntities.SaveChanges();
                //testEntities2.Review.Add(review);
                //testEntities2.SaveChanges();
                #endregion

                #region 自己生產的DbContext對象也沒有發生MSDTC
                //    base.Insert<Product>(product);
                base.Insert<Product_Comment>(product_Comment);
                new ReviewRepository().Insert<Review>(review);
                #endregion
                trans.Complete();
            }
        }
    }

測試環(huan)境:SQLSERVER2008在一臺服務器

     IIS7在別一臺服(fu)務器

感謝閱讀!

 

 回到目錄

posted @ 2013-01-16 17:43  張占嶺  閱讀(2007)  評論(0)    收藏  舉報