首页 > 代码库 > TransactionScope的用法

TransactionScope的用法

  using (TransactionScope ts = new TransactionScope())            {                Model.user_login_log model = new Model.user_login_log();                model.user_id = 0;                    model.user_name="";                    model.remark = Guid.NewGuid().ToString();                model.login_time=DateTime.Now;                model.login_ip=Request.UserHostAddress;                new BLL.user_login_log().Add(model);                model.user_id = 1;                new BLL.user_login_log().Add(model);               // throw new Exception("aaaaaaaaaaaaaaaa"); //在  ts.Complete();抛出异常,事物会自动回滚               // ts.Complete(); //显示提交事物,如果不显示提交,则事物相当于自动回滚,此代码不可少               // throw new Exception("bbbbbb"); 提交事物后抛出异常,不会影响事物                     Response.Write("ok");            }

 

TransactionScope的用法