private Boolean ExecuteSQL(string commandStr) { string tableName = ""; string operation = ""; bool autoInsert = false; SQLHandler.ParseTable(commandStr, ref tableName, ref operation); QueryResult query = new QueryResult(); //Declare a struct to record the query. ThreadHandler.LockThread(); // Lock the thread here for (int attempts = 0; attempts < 5; attempts++) { try { if (Log.Count > 200) { Log.Dequeue(); } using (SqlConnection connction = new SqlConnection(IntData.DestConn)) { query.Command = commandStr; connction.Open(); if (query.Command.Length > IntData.AUTO_INSERT_STR.Length) { if (query.Command.Substring(query.Command.Length - IntData.AUTO_INSERT_STR.Length, IntData.AUTO_INSERT_STR.Length) == IntData.AUTO_INSERT_STR) { query.Command = query.Command.Substring(0, query.Command.Length - IntData.AUTO_INSERT_STR.Length); autoInsert = true; } } SqlCommand command = new SqlCommand(query.Command, connction); query.Result = command.BeginExecuteNonQuery(); query.ExecuteTime = SqlLocker(query.Result); query.Completed = true; query.AffectedRecordsets = command.EndExecuteNonQuery(query.Result); Log.Enqueue(query.Command);//Queue the query. if (autoInsert && query.AffectedRecordsets == 0) { command.CommandText = SQLHandler.GenerateInsert(query.Command); query.Result = command.BeginExecuteNonQuery(); query.ExecuteTime = SqlLocker(query.Result); query.IsAutoInsert = true; query.Completed = true; query.AffectedRecordsets = command.EndExecuteNonQuery(query.Result); Log.Enqueue(query.Command);//Queue the qurey. } } break; } catch (Exception ex) { query.Completed = false; query.Command += "\t Error:" + ex.Message; Log.Enqueue(query.Command); query.RetryCount++; } } //insert log here ThreadHandler.ReleaseThread(); // Release the thread here return(true); }