0

我有以下代码调用存储过程,然后在另一张表上插入一个。

问题是,当该过程需要很少的时间来完成一切正常时,相反,当过程变得很长时间(会话似乎没有过期)但数据库上的下一个操作使会话“不活动”时

网络配置:

    </webServices>
    <trust level="Full" />
    <httpRuntime 
    executionTimeout="90000000" 
    maxRequestLength="2097151" 
    useFullyQualifiedRedirectUrl="false" 
    minFreeThreads="8" 
    minLocalRequestFreeThreads="4" 
    appRequestQueueLimit="1000" 
    enableVersionHeader="true"
    />

asp.net 页面:

    OracleCommand objCmd = new OracleCommand();
            objCmd.Connection = connection;
            objCmd.CommandText = "insertReqSched";
            objCmd.CommandType = CommandType.StoredProcedure;

            if((Session["chkAllSoc"] != null)&&(Session["chkAllSoc"].ToString() == "1"))
            {
                /*
                selezionare tutte le soc di vendita e metterli in una string separati da ,
                */
                OracleCommand cmd = new OracleCommand("select uidaccount FROM ACCOUNT A INNER JOIN ACCOUNTTYPE AT ON A.UIDACCOUNTTYPE = AT.UIDACCOUNTTYPE WHERE ACCOUNTTYPENAME IN ('RETAILER','ELIGIBLE_CLIENT') order by name asc",connection);
                 reader = cmd.ExecuteReader();
                string socVends = "";
                while (reader.Read())
                {
                    socVends = socVends + "" + reader.GetInt32(0) + ",";
                }
                reader.Close();

                OracleParameter socVal = new OracleParameter("socVend",OracleType.VarChar);
                socVal.Direction = ParameterDirection.Input;  
                socVal.Value= socVends.Remove(socVends.Length - 1);
                objCmd.Parameters.Add(socVal);
            }
            else{
                OracleParameter socVal = new OracleParameter("socVend",OracleType.VarChar);
                socVal.Direction = ParameterDirection.Input;  
                socVal.Value= ((Session["socVend"] != null) && (Session["socVend"].ToString().Length != 0)) ? Session["socVend"].ToString()  : (object)System.DBNull.Value;
                objCmd.Parameters.Add(socVal);
            }
            if((Session["chkAllPlant"]!= null)&&(Session["chkAllPlant"].ToString() == "1"))
            {
                /*
                selezionare tutti gli impianti e metterli in una stringa separati da ,
                */
                OracleCommand cmd = new OracleCommand("select plantcode from plant",connection);
                 reader = cmd.ExecuteReader();
                string plants = "";
                while (reader.Read())
                {
                    plants = plants + reader.GetString(0) + "," ;
                }
                reader.Close();

                OracleParameter plantCode = new OracleParameter("plantCode",OracleType.VarChar);
                plantCode.Direction = ParameterDirection.Input;  
                plantCode.Value= plants.Remove(plants.Length - 1);
                objCmd.Parameters.Add(plantCode);
            }
            else{
                OracleParameter plantCode = new OracleParameter("plantCode",OracleType.VarChar);
                plantCode.Direction = ParameterDirection.Input;  
                plantCode.Value= ((Session["plantcode"] != null) && (Session["plantcode"].ToString().Length != 0)) ? Session["plantcode"].ToString()  : (object)System.DBNull.Value;
                objCmd.Parameters.Add(plantCode);
            }
            OracleParameter bllingParam = new OracleParameter("billingcy",OracleType.VarChar);
            bllingParam.Direction = ParameterDirection.Input;  
            bllingParam.Value= ((Session["billingcycle"] != null )&&(Session["billingcycle"].ToString().Length != 0)) ? Session["billingcycle"].ToString()  : (object)System.DBNull.Value;
            objCmd.Parameters.Add(bllingParam);

            OracleParameter freqLet = new OracleParameter("freqLettura",OracleType.VarChar);
            freqLet.Direction = ParameterDirection.Input;  
            freqLet.Value= ((Session["freqLett"] != null )&&(Session["freqLett"].ToString().Length != 0)) ? Session["freqLett"].ToString()  : (object)System.DBNull.Value;
            objCmd.Parameters.Add(freqLet);

            OracleParameter tipoElab = new OracleParameter("tipoElab",OracleType.VarChar);
            tipoElab.Direction = ParameterDirection.Input;  
            tipoElab.Value= ((Session["tipoelab"] != null )&&(Session["tipoelab"].ToString().Length != 0)) ? Session["tipoelab"].ToString()  : (object)System.DBNull.Value;
            objCmd.Parameters.Add(tipoElab);

            OracleParameter startT = new OracleParameter("startTime",OracleType.DateTime);
            startT.Direction = ParameterDirection.Input;  
            startT.Value=Session["fStartDate"].ToString();
            objCmd.Parameters.Add(startT);

            OracleParameter stopT = new OracleParameter("stopTime",OracleType.DateTime);
            stopT.Direction = ParameterDirection.Input;  
            stopT.Value=Session["fEndDate"].ToString();
            objCmd.Parameters.Add(stopT);

            OracleParameter schedPara = new OracleParameter("schedDate",OracleType.DateTime);
            schedPara.Direction = ParameterDirection.Input;  
            schedPara.Value=Session["fSCHEDDATE"].ToString();
            objCmd.Parameters.Add(schedPara);

            OracleParameter seqVal = new OracleParameter("valoreSequence",OracleType.Number);
            seqVal.Direction = ParameterDirection.Input;  
            seqVal.Value = Convert.ToInt32(sequenceVal);
            objCmd.Parameters.Add(seqVal);


            objCmd.ExecuteNonQuery();


            OracleCommand cmdInsert = new OracleCommand("INSERT INTO batchrequest(uidbatchrequest,processnum,scheddate,starttime,stoptime,ratecode) " + 
            "  VALUES (:1,:2,:3,:4,:5,:6)", connection);
            cmdInsert.Parameters.Add("1", OracleType.Number).Value = Convert.ToInt32(sequenceVal);
            cmdInsert.Parameters.Add("2", OracleType.Number).Value = Convert.ToInt32(Session["selectProcess"]);
            cmdInsert.Parameters.Add("3", OracleType.DateTime).Value = date1;
            cmdInsert.Parameters.Add("4", OracleType.DateTime).Value = date2;
            cmdInsert.Parameters.Add("5", OracleType.DateTime).Value = date3;
            cmdInsert.Parameters.Add("6", OracleType.VarChar, 64).Value = Session["tipoelab"].ToString();
            try
            {
                cmdInsert.ExecuteNonQuery();
                Label1.Text = "Richiesta inserita correttamente";
                connection.Close();
                return;
            }   
            catch(Exception ex){

              OracleCommand cmd = connection.CreateCommand();
              cmd.CommandType = CommandType.Text;
              cmd.CommandText = "update batchrequest set scheddate = :1, starttime = :2, stoptime = :3, ratecode = 'S'  where scheddate = :keyValue";
              cmd.Parameters.Add("1", OracleType.DateTime).Value = date1;
              cmd.Parameters.Add("2", OracleType.DateTime).Value = date2;
              cmd.Parameters.Add("3", OracleType.DateTime).Value = date3;
              cmd.Parameters.Add("keyValue", OracleType.DateTime).Value = date1;

              try
              {
                cmd.ExecuteNonQuery();
                connection.Close();
              }   
              catch(Exception ee){
                    Label1.Text = "Richiesta inserita correttamente";
                    return;
              }

              Label1.Text = "Richiesta inserita correttamente";

              return;
            }
        }

我想强调的是,当程序花费很少的时间时,一切都很好。当最后一个命令需要很长时间时:插入或更新永远不会在数据库上停止,我看到会话处于非活动模式。

4

1 回答 1

0

如果查询花费的时间长于设置的 HTTP 超时时间,则最好创建一个数据库作业,然后从 ASP.NET 启动该作业,而无需等待它完成。

于 2013-06-11T13:50:17.000 回答