我按照上面那样写的话,就会提示:Sys.WebForms.PageRequestManagerServerErrorException: 发送信息异常,原因:Timeout 时间已到。在操作完成之前超时时间已过或服务器未响应。
语句已终止。

解决方案 »

  1.   

    然后我就把事务的作用范围缩小,代码这样写          //设置事务范围
                        TransactionOptions transactionOption = new TransactionOptions();
                        //设置事务隔离级别
                        transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; //不可以在事务期间读取可变数据,但是可以修改它
                        //RepeatableRead  可以在事务期间读取可变数据,但是不可以修改。 可以在事务期间添加新数据。
                        // 设置事务超时时间为60秒
                        //  transactionOption.Timeout = new TimeSpan(0, 0, 60);
                        using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required))
                        {
                            try
                            {                            if (DR.RowState == DataRowState.Detached)
                                {
                                    //nPracticeID = oAccess.GetMaxID("School_Practice", "PracticeID");  //先获取最新ID,用于跳转到显示页面
                                    DS.Tables[0].Rows.Add(DR);
                                    DA.Update(DS);
                                    // nPracticeID = oAccess.GetMaxID("School_Practice", "PracticeID") - 1;  //为了避免删除后获得的不是最新的id号,等添加了后再重新获取最新id号                            }
                                else if (DR.RowState == DataRowState.Modified)
                                {
                                    //DS.Tables[0].AcceptChanges();
                                    DA.Update(DS);
                                }                        //  System.Transactions.Transaction tr=System.Transactions.Transaction.Current;                            DS.Dispose();
                                DA.Dispose();
                                oBulider.Dispose();
                                UpdateHadPracticeHours(nStudentID, blAdd, strTimeCheckValue, strOldTimes); //更新预约时长  注意 先更新时长再更新预约时间
                                oDal.PracticeTimeUpdate(nPracticeID, strTimeCheckValue);                            //发送短信并记录发送结果
                                if (chkMobileSms.Checked)
                                {
                                    DataTable dt = oDal.PracticeTimeList(nPracticeID);
                                    jx.Models.Mobile.vxSms oSms = new Models.Mobile.vxSms();
                                    if (dt != null)
                                    {
                                        for (int i = 0; i < dt.Rows.Count; i++)
                                        {
                                            DataRow dr = dt.Rows[i];
                                            string strSms = Str(dr["PracticeName"]) + ",您好!您预约了" + Str(dr["CoachName"]) + "教练于" + Convert.ToDateTime(dr["PracticeDate2"]).ToString("M月d日") + " " + Str(dr["TimeBeg2"]) + "在金盘场地进行练习,请提前半小时到场报到,逾期自误。";
                                            string strSNO = "";
                                            bool Success = oSms.Send("", lg.ToInt(dr["StudentID"]), Str(dr["Mobile"]), strSms, ref strSNO);
                                            oDal.SmsUpdate(nPracticeID, Convert.ToDateTime(GetDate(dr["PracticeDate2"])), Str(dr["TimeBeg2"]), strSNO);
                                        }
                                    }
                                }                            oDal.oAccess.connectionClose();                            transaction.Complete();                        }
                            catch (Exception ex)
                            {
                                ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "", "很抱歉,学员没有预约成功!", true);
                                throw new Exception("发送信息异常,原因:" +ex.Message);                        }
                            finally
                            {
                                transaction.Dispose();                        }
                        }
    可以执行,但是好像中间执行错误的,还是照样进行下去,并没有回滚。感觉好像并没有执行事务的用法