I am running the following code. Following code is giving error on executenonquery line inside my SQL DataReader loop runs. I am getting
Exception Details: System.ComponentModel.Win32Exception: The wait operation timed out
I have tried mycomm.CommandTimeout = 600;
but it not helping.
I have executed these same statements in other projects it is working perfectly fine over there.
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection myconn, myconn1;
SqlCommand mycomm;
myconn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
myconn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
String q = "select * from addcart where sessionid=@sessid";
mycomm = new SqlCommand(q, myconn);
mycomm.Parameters.AddWithValue("@sessid", Session["sid"].ToString());
myconn.Open();
mycomm.CommandTimeout = 600;
SqlDataReader myreader;
myreader = mycomm.ExecuteReader();
if (myreader.HasRows)
{
while (myreader.Read())
{
myconn1.Open();
String qt = myreader["quantity"].ToString();
String bookid = myreader["bookid"].ToString();
q = "update addbook set stock=stock-@st where bid=@bid";
mycomm = new SqlCommand(q, myconn1);
mycomm.Parameters.AddWithValue("@st", qt);
mycomm.Parameters.AddWithValue("@bid", bookid);
mycomm.ExecuteNonQuery();//getting error on this line
myconn1.Close();
}
}
myconn.Close();
myconn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
q = "select * from newpayment where sessionid=@sessionid";
mycomm = new SqlCommand(q, myconn);
mycomm.Parameters.AddWithValue("@sessionid", Session["sid"]);
myconn.Open();
myreader = mycomm.ExecuteReader();
myreader.Read();
Label2.Text = myreader["orderno"].ToString();
Label3.Text = myreader["billamount"].ToString();
Label4.Text = myreader["address"].ToString();
myreader.Close();
myconn.Close();
}