I use the SqlConnection class and run problems with expiring the command.
First, I use the SqlCommand property to set the command timeout as follows:
command.CommandTimeout = 300;
In addition, I found that the Runtime Timeout parameter is set to 0 to ensure that there are no timeouts on the SQL management side.
Here is my code:
using (SqlConnection conn = new SqlConnection(connection)) { conn.Open(); SqlCommand command = conn.CreateCommand(); var transaction = conn.BeginTransaction("CourseLookupTransaction"); command.Connection = conn; command.Transaction = transaction; command.CommandTimeout = 300; try { command.CommandText = "TRUNCATE TABLE courses"; command.ExecuteNonQuery(); List<Course> courses = CourseHelper.GetAllCourses(); foreach (Course course in courses) { CourseHelper.InsertCourseLookupRecord(course); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); Log.Error(string.Format("Unable to reload course lookup table: {0}", ex.Message)); } }
I installed the registration and can check exactly 30 seconds after disabling this function, I get the following error message in my stack trace:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
In the interest of full disclosure: InsertCourseLookupRecord() , found inside the above statements using foreach, executes another query to the same table in the same database. Here is the query that it executes:
INSERT INTO courses(courseid, contentid, name, code, description, url, metakeywords, metadescription) VALUES(@courseid, @contentid, @name, @code, @description, @url, @metakeywords, @metadescription)"
This table contains over 1,400 entries.
I certify any person (s) who will help me resolve this as the greatest great wizard.