Eslam Amgad

Eslam Amgad

  • NA
  • 1
  • 0

SQLCommand Timeout expired

Aug 3 2010 4:24 AM

Dear Helpers,
I Have a strange problem with this code:
string myConstr="Data Source=.;Initial Catalog=Corp;Integrated Security=True";
SqlCommand updCmd = new SqlCommand();
updCmd.CommandText = "UPDATE .....";
using (updCmd.Connection = new SqlConnection(myConstr))
                        {
                            updCmd.Connection.Open();

                            //myCon2.Open();
                            try
                            {
                                GC.Collect();
                                int dr = updCmd.ExecuteNonQuery();
                                GC.Collect();
                            }
                            catch
                            {
                                
                            }
                            updCmd.Connection.Close();
                            updCmd.Connection.Dispose();
                        }
 
This UPDATE command takes 1 sec. from my microsoft sql server management studio query.
This code block is in a loop.
This UPDATE command "ExecuteNonQuery()" is ok for about the first 20 loop and then throws this exception:
"Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding."
 

Answers (1)