我正在研究asp.net项目。我在这里添加一个新页面,在该页面上我调用多个存储过程。执行此页面一段时间后,我的网站停止工作并继续刷新浏览器而不会出现任何错误。重新启动服务器后,它再次开始工作。
private void GetBiometrixData()
{
try
{
string data = string.Empty;
var length = ddlsession.Items.Count;
for (int i = 0; i < length; i++)
{
if (ddlsession.Items[i].Selected == true)
{
if (ddlsession.Items[i].Text != "--Select--")
{
data += ddlsession.Items[i].Text + ",";
}
}
}
data = data.Length > 0 ? data.Substring(0, data.Length - 1) : "";
data = data.Trim();
String strConnString = ConfigurationManager.ConnectionStrings["ak"].ConnectionString;
DateTime? FromDate = null;
DateTime? ToDate = null;
string session = "";
string TrainingType = "";
string EmployeeName = "";
string Course = "";
string Batch = "";
CultureInfo provider = CultureInfo.InvariantCulture;
string format = "MM/dd/yyyy";
if (string.IsNullOrEmpty(txtFromDate.Text.ToString()))
{
string TodayDate = DateTime.Now.ToString("MM/dd/yyyy");
FromDate = DateTime.ParseExact(TodayDate.ToString().Trim(), format, provider);
}
else
FromDate = DateTime.ParseExact(txtFromDate.Text.ToString().Trim(), format, provider);
if (string.IsNullOrEmpty(txtToDate.Text.ToString()))
ToDate = null;
else
ToDate = DateTime.ParseExact(txtToDate.Text.ToString().Trim(), format, provider);
if (ddlsession.SelectedItem.Text.ToString() == "--Select--")
session = null;
else
session = ddlsession.SelectedItem.Text.ToString();
if ((ddltrainingtype.SelectedItem.Text.ToString() == "--Select Training Type--"))
TrainingType = null;
else
TrainingType = ddltrainingtype.SelectedItem.Text.ToString();
if ((ddlCourse.SelectedItem.Text.ToString() == "--Select Course--"))
Course = null;
else
Course = ddlCourse.SelectedValue.ToString();
if ((ddlbatch.SelectedItem.Text.ToString() == "--Select Batch--"))
Batch = null;
else
Batch = ddlbatch.SelectedValue.ToString();
if (!string.IsNullOrEmpty(txtEmployeeName.Text.ToString()))
EmployeeName = txtEmployeeName.Text.ToString();
string strStatus = "";
if (Session["strStatus"] != null)
{
strStatus = Convert.ToString(Session["strStatus"]);
}
DataSet dsCount = new DataSet();
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.CommandTimeout = 0;
cmd.CommandText = "SP_GetBiometricAttendanceReport2";
cmd.Parameters.Add("@FromDate", System.Data.SqlDbType.DateTime).Value = FromDate;
cmd.Parameters.Add("@ToDate", System.Data.SqlDbType.DateTime).Value = ToDate;
cmd.Parameters.Add("@Session", SqlDbType.VarChar).Value = data;
cmd.Parameters.Add("@TrainingType", SqlDbType.VarChar).Value = TrainingType;
cmd.Parameters.Add("@Course", SqlDbType.VarChar).Value = Course;
cmd.Parameters.Add("@Batch", SqlDbType.VarChar).Value = Batch;
cmd.Parameters.Add("@EmployeeName", SqlDbType.VarChar).Value = EmployeeName;
cmd.Parameters.Add("@TotalStudents", SqlDbType.BigInt);
cmd.Parameters["@TotalStudents"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@TotalPresentStudents", SqlDbType.BigInt);
cmd.Parameters["@TotalPresentStudents"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@TotalAbsentStudents", SqlDbType.BigInt);
cmd.Parameters["@TotalAbsentStudents"].Direction = ParameterDirection.Output;
sda.SelectCommand = cmd;
sda.Fill(dsCount);
tblSummary.Visible = true;
lblTotalDrive.Text = cmd.Parameters["@TotalStudents"].Value.ToString();
lblTotalStudentAttended.Text = cmd.Parameters["@TotalPresentStudents"].Value.ToString();
lblTotalStudentAbsent.Text = cmd.Parameters["@TotalAbsentStudents"].Value.ToString();
}
}
}
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
if (!string.IsNullOrEmpty(Convert.ToString(FromDate)) && !string.IsNullOrEmpty(Convert.ToString(ToDate)))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.CommandTimeout = 0;
cmd.CommandText = "SP_GetBiometricAttendanceReportCount";
cmd.Parameters.Add("@FromDate", System.Data.SqlDbType.DateTime).Value = FromDate;
cmd.Parameters.Add("@ToDate", System.Data.SqlDbType.DateTime).Value = ToDate;
cmd.Parameters.Add("@Session", SqlDbType.VarChar).Value = data;
cmd.Parameters.Add("@TrainingType", SqlDbType.VarChar).Value = TrainingType;
cmd.Parameters.Add("@Course", SqlDbType.VarChar).Value = Course;
cmd.Parameters.Add("@Batch", SqlDbType.VarChar).Value = Batch;
cmd.Parameters.Add("@EmployeeName", SqlDbType.VarChar).Value = EmployeeName;
sda.SelectCommand = cmd;
sda.Fill(ds);
tblSummary.Visible = false;
GridView2.Visible = false;
RadGrid1.Visible = false;
GridView1.Visible = true;
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
//RadGrid1.DataSource = ds.Tables[0];
//RadGrid1.Rebind();
}
else
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.CommandTimeout = 0;
cmd.CommandText = "SP_GetBiometricAttendanceReport";
cmd.Parameters.Add("@FromDate", System.Data.SqlDbType.DateTime).Value = FromDate;
cmd.Parameters.Add("@ToDate", System.Data.SqlDbType.DateTime).Value = ToDate;
cmd.Parameters.Add("@Session", SqlDbType.VarChar).Value = session;
cmd.Parameters.Add("@TrainingType", SqlDbType.VarChar).Value = TrainingType;
cmd.Parameters.Add("@Course", SqlDbType.VarChar).Value = Course;
cmd.Parameters.Add("@EmployeeName", SqlDbType.VarChar).Value = EmployeeName;
cmd.Parameters.Add("@Status", SqlDbType.VarChar).Value = strStatus;
cmd.Parameters.Add("@Batch", SqlDbType.VarChar).Value = Batch;
sda.SelectCommand = cmd;
sda.Fill(ds);
GridView2.DataSource = ds.Tables[0];
GridView2.DataBind();
RadGrid1.DataSource = ds.Tables[0];
RadGrid1.Rebind();
if (strStatus == "")
lblResultStatus.Text = "<strong>Result of Total Students >></strong>";
else
lblResultStatus.Text = "<strong>Result of Total " + strStatus + " Students >></strong>";
}
}
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
//throw ex;
}
finally
{
con.Dispose();
con.Close();
}
}
请帮我解决一下为什么网站停止正常工作并需要一次又一次重启服务器。
...谢谢