0
using (SqlConnection connection1 = new SqlConnection(StringCon))
{
    string sSQL = string.Format("UPDATE Guest SET FirstName=@Content WHERE GuestID=@GuestID");
    SqlCommand MyCmd = new SqlCommand(sSQL, connection1);
    SqlParameter param = MyCmd.Parameters.Add("@Content", SqlDbType.NVarChar);
    param.Value = "Tony";
    SqlParameter param1 = MyCmd.Parameters.Add("@GuestID", SqlDbType.NVarChar);
    param1.Value = GuestID;
    connection1.Open();
    iResult = MyCmd.ExecuteNonQuery();
    connection1.Close();
}

But this code cannot execute because this error

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated.

Why have error and how to fix it.

p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
TonyTTH
  • 1
  • 1
  • What happens when you run that statement by hand? Maybe there's a trigger on the table taking too long, or there's no index on the table, or the table is locked, etc. – scott.korin Mar 18 '13 at 03:14

1 Answers1

0

Well it appears that this command is taking longer than you anticipated, you can try to specify the timeout for your SqlCommand (extend it to whatever you see fit for the situation):

SqlCommand MyCmd = new SqlCommand(sSQL, connection1);
MyCmd.CommandTimeout = 1000; // in seconds
Dimitar Dimitrov
  • 14,868
  • 8
  • 51
  • 79