public ErrorLogMetrics get_error_counts() { var counts = new ErrorLogMetrics(); const string sql = @"select top 1 * from ProductionSupport.dbo.Dashboard_ErrorCounts_Keep where CurrentDate = ( select MAX(CurrentDate) from ProductionSupport.dbo.Dashboard_ErrorCounts_Keep)"; var select_cmd = new SqlCommand(sql); select_cmd.Connection = (SqlConnection)db_connection; if (db_connection.State == ConnectionState.Closed) db_connection.Open(); var reader = select_cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { counts = build_error_counts_from_reader(reader); } if (db_connection.State == ConnectionState.Open) db_connection.Close(); return counts; }
ErrorLogMetrics build_error_log_from_reader(SqlDataReader reader) { var metric = new ErrorLogMetrics(); metric.error_count = reader.GetInt32(1); metric.error = reader.GetString(2); return metric; }
ErrorLogMetrics build_error_counts_from_reader(SqlDataReader reader) { var counts = new ErrorLogMetrics(); counts.current_date = reader.GetDateTime(3); counts.current_error_count = reader.GetInt32(4); counts.past_date = reader.GetDateTime(1); counts.past_error_count = reader.GetInt32(2); return counts; }