-1

This is my stored procedure for update teacher detail

 ALTER procedure [dbo].[sp_update_teacher]
     (@teacherid int,
      @name varchar(50),
      @gender int,
      @email varchar(50),
      @phone varchar(50),
      @address varchar(50),
      @timage image)
as
    update teacher_info 
    set teacher_name = @name,
        gender_id = @gender,
        teacher_mail = @email,
        phone = @phone,
        teacher_address = @address,
        image = @timage 
    where teacher_id = @teacherid

This is ado.net class code for update teacher detail

    public void update_info(int teacher_id, string teacher_name, int teacher_gender, string email, string teacher_phone, string teacher_address, byte[] image)
    {

        SqlConnection con = new SqlConnection("server=ARMAAN;database=smsystem;integrated security=true;");
        SqlCommand cmd = new SqlCommand("sp_update_teacher", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@teacherid", teacher_id);
        cmd.Parameters.AddWithValue("@name", teacher_name);
        cmd.Parameters.AddWithValue("@gender", teacher_gender);
        cmd.Parameters.AddWithValue("@email", email);
        cmd.Parameters.AddWithValue("@phone", teacher_phone);
        cmd.Parameters.AddWithValue("@address", teacher_address);
        cmd.Parameters.AddWithValue("@timage", image);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }
}

This is update page code where i call the function that i i have made in class code

 protected void update_Click1(object sender, EventArgs e)

 {
    try
            {
                FileUpload img = (FileUpload)FileUpload2;
                Byte[] imgbyte = null;

                HttpPostedFile file = FileUpload2.PostedFile;
                imgbyte = new Byte[file.ContentLength];
                file.InputStream.Read(imgbyte, 0, file.ContentLength);

                tic.update_info(Convert.ToInt32(txt_id.Text), txt_name.Text, Convert.ToInt32(txt_genders.SelectedValue),txt_email.Text,txt_phone.Text, txt_address.Text, imgbyte);
                Response.Write("<script language='javascript'>alert('Teacher detail Update successfully') </script>");
                GridView1.DataSource = tic.getdata();
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("<script language='javascript'>alert('some error') </script>");
            }

        }

and it give me this error please tell me what should I do?

  • which line do you encounter this error? – techspider Apr 26 '16 at 21:19
  • cmd.ExecuteNonQuery(); – Armaan Arain Apr 26 '16 at 21:21
  • @techspider when i update my data compiler stop on this line and give me this error Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding – Armaan Arain Apr 26 '16 at 21:24
  • 1
    Side note: you should **not** use the `sp_` prefix for your stored procedures. Microsoft has [reserved that prefix for its own use (see *Naming Stored Procedures*)](http://msdn.microsoft.com/en-us/library/ms190669%28v=sql.105%29.aspx), and you do run the risk of a name clash sometime in the future. [It's also bad for your stored procedure performance](http://www.sqlperformance.com/2012/10/t-sql-queries/sp_prefix). It's best to just simply avoid `sp_` and use something else as a prefix - or no prefix at all! – marc_s Apr 26 '16 at 21:27
  • 1
    `ntext`, `text`, and `image` data types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use `nvarchar(max)`, `varchar(max)`, and `varbinary(max)` instead. [See details here](http://msdn.microsoft.com/en-us/library/ms187993.aspx) – marc_s Apr 26 '16 at 21:27
  • what version of sql server are you using? – Nate Anderson Apr 26 '16 at 21:51
  • @nate sql server 2012 – Armaan Arain Apr 26 '16 at 22:17
  • spitballing, but are you able to change the image datatype to a varbinary(max) field? – Nate Anderson Apr 26 '16 at 23:29
  • 3
    Possible duplicate of [Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated](http://stackoverflow.com/questions/8602395/timeout-expired-the-timeout-period-elapsed-prior-to-completion-of-the-operation) – Ehsan Sajjad Dec 23 '16 at 11:33

1 Answers1

0

Try increasing the command timeout of the command:

    cmd.CommandTimeout = 120;

CommandTimeout

Nate Anderson
  • 690
  • 4
  • 20