Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void SaveAttachements(Int64 noticeDetailID)
  {
      try
      {
          if (gvAttachments.Rows.Count > 0)
          {
              String Sql = string.Empty;
              if ((Session["FileDetail"].ToString() !=""))
              {
                  string[] Records = Session["FileDetail"].ToString().Split('#');
                  for (int i = 0; i < Records.Length; i++)
                  {
                      string[] arrRecords = Records[i].Split(',');
                      cmd = new SqlCommand();
                      cmd.CommandText = "select File_Name,File_Format,File_Content from Temporary_Attachment Where File_ID='" + arrRecords[1] + "'";
                      cmd.CommandType = CommandType.Text;
                      cmd.Connection = con;
                      SqlDataReader dr = cmd.ExecuteReader();
                      while (dr.Read())
                      {

                          cmd = new SqlCommand();
                          Sql = "Insert  into Notice_Attachment(File_Name,File_Format,File_Content,Notice_Detail_ID) values ('" + dr["File_Name"].ToString() + "','" + dr["File_Format"].ToString() + "',(Select top(1) File_Content from Temporary_Attachment Where File_ID='" + arrRecords[1] + "')," + noticeDetailID + ")";
                          cmd.CommandText = Sql;
                          cmd.CommandType = CommandType.Text;
                          cmd.Connection = con;
                          cmd.ExecuteNonQuery();
                          Sql = "Delete from Temporary_Attachment Where File_ID='" + arrRecords[1] + "'";
                          cmd.CommandText = Sql;
                          cmd.CommandType = CommandType.Text;
                          cmd.Connection = con;
                          cmd.ExecuteNonQuery();

                      }
                  }
              }
          }
      }
      catch (Exception ex)
      {

      }
  }



Please Help??
Posted
Comments
Kumarbs 25-Jul-14 5:54am    
Try it by adding cmd.commandtimeout =0. And i afraid to say working with the raw sql statements within the loops is a bad practise, instead you can go with StoredProcedure.
Neha Mukesh 25-Jul-14 6:09am    
cmd.CommandTimeout = 0; is also not working
Kumarbs 25-Jul-14 6:16am    
Then try to make a single statement by merging insert and select statements. Because you are looping many times. Or the best way is create a stored procedure.
King Fisher 25-Jul-14 6:11am    
cmd.CommandTimeout = 300;

set the Timeout whatever you want

1 solution

Try increasing time out by:
C#
cmd.TimeOut=180;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900