首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >超时过期了。从池获得连接之前经过的超时时间。

超时过期了。从池获得连接之前经过的超时时间。
EN

Stack Overflow用户
提问于 2012-03-03 06:54:07
回答 1查看 1.1K关注 0票数 0

当我上传包含提交urls的excel表时,我遇到了一个问题,我想要将excel的每条记录与db数据匹配--当我上传一个很好的小文件时,它工作得很好--但是如果有2MB文件,那么就会有异常:Details 超时过期了。从池获得连接之前经过的超时时间。这可能是因为所有池连接都在使用,并且达到了最大池大小。

这是我的密码

代码语言:javascript
复制
 protected void btnUpload_Click(object sender, EventArgs e)
    {
        if ((txtFilePath.HasFile))
        {

            OleDbConnection conn = new OleDbConnection();
            OleDbCommand cmd = new OleDbCommand();
            OleDbDataAdapter da = new OleDbDataAdapter();
            DataSet ds = new DataSet();
            string query = null;
            string connString = "";
            string strFileName = DateTime.Now.ToString("sddMMyyyy_LOFTY");
            string strFileType = System.IO.Path.GetExtension(txtFilePath.FileName).ToString().ToLower();

            //Check file type
            if (strFileType == ".xls" || strFileType == ".xlsx")
            {
                txtFilePath.SaveAs(Server.MapPath("~/AdminCpanel/UploadedExcel/" + strFileName + strFileType));
            }
            else
            {
                lblMessage.Text = "Only excel files allowed";
                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Visible = true;
                return; 
            }

            string strNewPath = Server.MapPath("~/AdminCpanel/UploadedExcel/" + strFileName + strFileType);

            //Connection String to Excel Workbook
            if (strFileType.Trim() == ".xls")
            {
                connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strNewPath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
            }
            else if (strFileType.Trim() == ".xlsx")
            {
                connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strNewPath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
            }

            // Sheet name is Ads Posted
            query = "SELECT * FROM [Ads Posted$]";
            //Create the connection object
            conn = new OleDbConnection(connString);
            //Open connection
            if (conn.State == ConnectionState.Closed) conn.Open();
            //Create the command object
            cmd = new OleDbCommand(query, conn);
            da = new OleDbDataAdapter(cmd);
            ds = new DataSet();
            da.Fill(ds, "validateLog");


            //// Sheet name is Details
            //query = "SELECT * FROM [Details$]";
            ////Create the connection object
            //conn = new OleDbConnection(connString);
            ////Open connection
            //if (conn.State == ConnectionState.Closed) conn.Open();
            ////Create the command object
            //cmd = new OleDbCommand(query, conn);
            //da = new OleDbDataAdapter(cmd);
            //DataSet dsdetails = new DataSet();
            //da.Fill(dsdetails, "Details");

            DateTime dtStartdate =Convert.ToDateTime(txtFromDate.Text);
            DateTime dtEndDate = Convert.ToDateTime(txtEndDate.Text);






            DataColumn dColumn = new DataColumn();
            dColumn.DataType = System.Type.GetType("System.String");
            dColumn.ColumnName = "Status";
            ds.Tables[0].Columns.Add(dColumn);


            bool flag = false;
            if (ds.Tables[0].Rows.Count > 0)
            {

                RegistrationDB db = new RegistrationDB();
                DataTable dtAds = db.GetPostedAdstoValidate(ds.Tables[0].Rows[1]["LoftyID"].ToString());
                //excel sheet
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (Convert.ToDateTime(ds.Tables[0].Rows[i]["Date"].ToString()) <= dtEndDate && Convert.ToDateTime(ds.Tables[0].Rows[i]["Date"].ToString()) >= dtStartdate)
                    {
                        //db table
                        for (int z = 0; z < dtAds.Rows.Count; z++)
                        {


                            if (ds.Tables[0].Rows[i]["LoftyAddURL"].ToString() == dtAds.Rows[z]["URL"].ToString())
                            {
                                ds.Tables[0].Rows[i]["Status"] = "Validated!";
                                flag = true;
                                break;
                            }
                            else if (ds.Tables[0].Rows[i]["IPAddress"].ToString() == dtAds.Rows[z]["IPAddress"].ToString())
                            {
                                ds.Tables[0].Rows[i]["IPAddress"] = "Valid IP!";
                                flag = true;
                                break;
                            }

                            flag = false;
                        }
                    }
                    else
                    {
                        flag = true;
                        ds.Tables[0].Rows[i]["Status"] = "Date does not lie between Project start and end date!";
                        ds.Tables[0].Rows[i]["IPAddress"] = "InvalidIP / EmptyIP";

                    }
                    if (!flag)
                        ds.Tables[0].Rows[i]["Status"] = "Not Validated!";
                       //ds.Tables[0].Rows[i]["IPAddress"] = "Invalid IP";

                }

            }

            //ds.Tables[0].Columns.Remove("F5");
            //ds.Tables[0].Columns.Remove("F6");
            //ds.Tables[0].Columns.Remove("F7");
            grvExcelData.DataSource = ds.Tables[0];
            grvExcelData.DataBind();
            //dump to database for logging
            ViewState["MyGridViewDate"]=ds.Tables[0];
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
               RegistrationDB dump = new RegistrationDB();
               string Loftyid = ds.Tables[0].Rows[i]["Loftyid"].ToString();
               string Date = ds.Tables[0].Rows[i]["Date"].ToString();
               string LoftyAddURL = ds.Tables[0].Rows[i]["LoftyAddURL"].ToString();
               string Status = ds.Tables[0].Rows[i]["Status"].ToString();
               string Addno = ds.Tables[0].Rows[i]["Addno"].ToString();
               string IPAddress = ds.Tables[0].Rows[i]["IPAddress"].ToString();
               dump.CreateLogValidation(Loftyid, Date, LoftyAddURL, Status, Addno,IPAddress); 
            }




            lblMessage.Text = "Data retrieved successfully! Total Recodes:" + ds.Tables[0].Rows.Count;
            lblMessage.ForeColor = System.Drawing.Color.Green;
            lblMessage.Visible = true;

            //da.Dispose();
            //conn.Close();
           // conn.Dispose();
        }
        else
        {
            lblMessage.Text = "Please select an excel file first";
            lblMessage.ForeColor = System.Drawing.Color.Red;
            lblMessage.Visible = true;
        }
    }

感谢事先的帮助,会非常感谢大家。

EN

回答 1

Stack Overflow用户

发布于 2012-03-03 15:58:59

增加最大上载大小

4MB默认设置为machine.config,但您可以在web.config中重写它。例如,要将上传限制扩大到20 to,您可以这样做:

代码语言:javascript
复制
   <system.web>
   <httpRuntime executionTimeout="240" maxRequestLength="20480" />
   </system.web>

由于最大的请求大小限制是为了保护您的站点,所以最好扩展特定目录的文件大小限制,而不是整个应用程序。这是可能的,因为web.config允许级联覆盖。您可以将一个web.config文件添加到只包含上述内容的文件夹中,也可以使用主web.config中的标记来达到同样的效果:

代码语言:javascript
复制
   <location path="Upload">
   <system.web>
    <httpRuntime executionTimeout="110" maxRequestLength="20000" />
   </system.web>
  </location>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9544190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档