使用 System.Transactions 进行事物管理
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Transactions; namespace DTcms.Web.aspx.main { public partial class test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { bind(); } private void bind() { 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); new BLL.user_login_log().Add(model); throw new Exception("aaaaaaaaaaaaaaaa"); ts.Complete(); Response.Write("ok"); } } } }