1
Answer

SQLCommand Timeout expired

Eslam Amgad

Eslam Amgad

14y
2.7k
1

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)