.net 超时已过期。从池中获取连接之前经过的超时时间
当我上传包含提交URL的excel表时,我有一个问题,我想将excel的每个记录与db数据匹配。当我上传一个小文件时,它工作正常,但如果有2MB文件,则有例外:详细信息 超时已过期。从池中获取连接之前经过的超时时间。发生这种情况的原因可能是所有池连接都在使用中,并且达到了最大池大小。 这是我的密码.net 超时已过期。从池中获取连接之前经过的超时时间,.net,connection-pooling,.net,Connection Pooling,当我上传包含提交URL的excel表时,我有一个问题,我想将excel的每个记录与db数据匹配。当我上传一个小文件时,它工作正常,但如果有2MB文件,则有例外:详细信息 超时已过期。从池中获取连接之前经过的超时时间。发生这种情况的原因可能是所有池连接都在使用中,并且达到了最大池大小。 这是我的密码 protected void btnUpload_Click(object sender, EventArgs e) { if ((txtFilePath.HasFile))
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;
}
}
protectedvoidbtnupload\u单击(对象发送方,事件参数e)
{
if((txtFilePath.HasFile))
{
OleDbConnection conn=新的OleDbConnection();
OleDbCommand cmd=新的OleDbCommand();
OleDbDataAdapter da=新的OleDbDataAdapter();
数据集ds=新数据集();
字符串查询=null;
字符串connString=“”;
字符串strFileName=DateTime.Now.ToString(“sddMMyyyy_”);
字符串strFileType=System.IO.Path.GetExtension(txtFilePath.FileName.ToString().ToLower();
//检查文件类型
if(strFileType==“.xls”| | strFileType==“.xlsx”)
{
SaveAs(Server.MapPath(“~/AdminCpanel/UploadedExcel/”+strFileName+strFileType));
}
其他的
{
lblMessage.Text=“仅允许excel文件”;
lblMessage.ForeColor=System.Drawing.Color.Red;
lblMessage.Visible=true;
返回;
}
字符串strNewPath=Server.MapPath(“~/AdminCpanel/UploadedExcel/”+strFileName+strFileType);
//Excel工作簿的连接字符串
if(strFileType.Trim()==“.xls”)
{
connString=“Provider=Microsoft.Jet.OLEDB.4.0;数据源=“+strNewPath+”“扩展属性=\”Excel 8.0;HDR=Yes;IMEX=2\”;
}
else if(strFileType.Trim()=“.xlsx”)
{
connString=“Provider=Microsoft.ACE.OLEDB.12.0;数据源=“+strNewPath+”“扩展属性=\”Excel 12.0;HDR=Yes;IMEX=2\”;
}
//表名是张贴的广告
query=“从[Ads Posted$]中选择*”;
//创建连接对象
conn=新的OLEDB连接(connString);
//开放连接
如果(conn.State==ConnectionState.Closed)conn.Open();
//创建命令对象
cmd=新的OleDbCommand(查询,连接);
da=新的OLEDB数据适配器(cmd);
ds=新数据集();
da.填写(ds,“验证日志”);
////工作表名称是详细信息
//query=“从[Details$]中选择*”;
////创建连接对象
//conn=新的OLEDB连接(connString);
////开放连接
//如果(conn.State==ConnectionState.Closed)conn.Open();
////创建命令对象
//cmd=新的OleDbCommand(查询,连接);
//da=新的OLEDB数据适配器(cmd);
//数据集dsdetails=新数据集();
//da.填写(dsdetails,“细节”);
DateTime dtStartdate=Convert.ToDateTime(txtFromDate.Text);
DateTime dtEndDate=Convert.ToDateTime(txtEndDate.Text);
DataColumn dColumn=新的DataColumn();
dColumn.DataType=System.Type.GetType(“System.String”);
dColumn.ColumnName=“状态”;
ds.Tables[0].Columns.Add(dColumn);
布尔标志=假;
如果(ds.Tables[0].Rows.Count>0)
{
RegistrationDB=新的RegistrationDB();
DataTable dtAds=db.getPostedStatovalidate(ds.Tables[0].Rows[1][“LoftyID”].ToString());
//excel表格
对于(int i=0;i <system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
<location path="Upload">
<system.web>
<httpRuntime executionTimeout="110" maxRequestLength="20000" />
</system.web>
</location>