Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to update fields and the code has no errors but when it gets to ExcecuteNonQuery() the program freezes for about 15 seconds then throws an errors saying timeout expired. The update stored procedure works perfectly fine.

Below is the code for the update method.
C#
public void UpdateChurch(Church church)
{
    using (SqlConnection con = new SqlConnection(connectionString))
    {
        dbConn.Open();
        SqlCommand cmd = new SqlCommand("sp_UpdateChurchInfo", con);
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.Add(new SqlParameter("@ChurchID", SqlDbType.Int));
        cmd.Parameters["@ChurchID"].Value = church.ChurchID;

        cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 50));
        cmd.Parameters["@Name"].Value = church.Name;

        cmd.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar));
        cmd.Parameters["@Address"].Value = church.Address;

        cmd.Parameters.Add(new SqlParameter("@SubCode", SqlDbType.Int));
        cmd.Parameters["@SubCode"].Value = church.SubCode;

        cmd.Parameters.Add(new SqlParameter("@City", SqlDbType.NVarChar, 50));
        cmd.Parameters["@City"].Value = church.City;

        cmd.Parameters.Add(new SqlParameter("@Tell", SqlDbType.NVarChar, 10));
        cmd.Parameters["@Tell"].Value = church.Tell;

        cmd.Parameters.Add(new SqlParameter("@Fax", SqlDbType.NVarChar, 10));
        cmd.Parameters["@Fax"].Value = church.Fax;

        cmd.Parameters.Add(new SqlParameter("@EmailAddress", SqlDbType.NVarChar, 50));
        cmd.Parameters["@EmailAddress"].Value = church.EmailAddress;

        cmd.Parameters.Add(new SqlParameter("@WebAddress", SqlDbType.NVarChar, 50));
        cmd.Parameters["@WebAddress"].Value = church.WebAddress;

        cmd.Parameters.Add(new SqlParameter("@NoOfMembers", SqlDbType.Int));
        cmd.Parameters["@NoOfMembers"].Value = church.NoOfMembers;

        cmd.CommandTimeout = 180;

        try
        {
            cmd.Connection.Open();
            cmd.ExecuteNonQuery();  //here is where the problem occurs.

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error",
            MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

    }
}
Posted
Updated 18-Aug-14 3:11am
v2

1 solution

I think change session time out in web.config file, so try it out.
 
Share this answer
 
Comments
Rudolfskow 19-Aug-14 6:12am    
I already tried that, that is why i have this line of code [cmd.CommandTimeout = 180;]
but both of them does not seem to be working.

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