Asp.net经过漫长的过程后,下一个操作无法完成

本文关键字:操作 下一个 经过 net 漫长的 过程 Asp | 更新日期: 2023-09-27 18:18:04

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

问题是,当过程花费很少的时间来完成时,一切都很顺利,当过程得到很长的时间(会话似乎没有过期),但对db的下一个操作使会话"非活动"

web . config:

    </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;
            }
        }

我想强调的是,当过程花费很少的时间,一切都很好。当花费很长时间的最后一个命令:插入或更新从未停止在数据库上,我看到会话在不活跃的模式。

Asp.net经过漫长的过程后,下一个操作无法完成

如果查询花费的时间很长,超过设置的HTTP超时,那么您最好创建一个数据库作业,并从ASP启动该作业。. NET,而不等待它完成。