I'm with the following problem, I have an application that is responsible for generating queries through ReportViewer, the application connects to a MariaDB10 Database that handles approximately 19 million records, the data is stored by an external application that collects information of processes in a plant.
That application automatically generates its structure of tables, for the reporting system only a table is required where all the production data is stored, because that data is in a single table with only two fields to order what we use is pivot to sort the information according to the requirement of each report, one of the generated reports is throwing an exception when generating parameters parameterized by dates when selecting parameters of times of more than 20 days the report throws the exception, when reviewing the code we could see that the exception is generated just after executing the pivot query, we executed that query from the terminal directly in the database server the query took a little while to generate but in the end it did not give any error and it could generate the results.
I include the mentioned query and the line where the error is generated is "MySqlDataReader hist = histoform.ExecuteReader ();"
/*HISTORIAL FORMULA*/
string val = "", valu="";
int exitval = 0;
MySqlCommand histoform = new MySqlCommand("SELECT EVTTIME, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SET_CEMENTO' THEN ROUND(d.evtvalue) END) AS CEM, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SET_CARBONATO' THEN ROUND(d.evtvalue) END) AS CAR, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SK_SETCELULOSAVIRGEN' THEN ROUND(d.evtvalue) END) AS CVIR, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SK_SETCELULOSADKL' THEN ROUND(d.evtvalue) END) AS CDKL, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SK_SETPVA' THEN ROUND(d.evtvalue) END) AS PVA, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SK_SETHIDROFUGANTE' THEN ROUND(d.evtvalue) END) AS HID, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SET_LODO' THEN ROUND(d.evtvalue) END) AS LOD, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SET_FILLER' THEN ROUND(d.evtvalue) END) AS FIB, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SET_CELULOSA' THEN ROUND(d.evtvalue) END) AS DCEL, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SK_SETFORMULAOTROS' THEN ROUND(d.evtvalue) END) AS OTR, SUM(DISTINCT CASE WHEN c.H_MNEMO = 'SK_VALCODIGOFORMULMATPRIM' THEN ROUND(d.evtvalue) END) AS FORM FROM DATOSDT D,configuration c WHERE c.evtcellule = d.evtcellule AND EVTTIME BETWEEN '" + fecinic + "' AND '" + fecfinc + "' GROUP BY d.EVTTIME HAVING FORM IS NOT NULL ORDER BY d.EVTTIME DESC;", con.conected());
MySqlDataReader hist = histoform.ExecuteReader();
if (hist.HasRows)
{
while (hist.Read())
{
if (hist[1].ToString() != "" && hist[2].ToString() != "" && hist[3].ToString() != "" && hist[4].ToString() != "" && hist[5].ToString() != "" && hist[6].ToString() != "" && hist[7].ToString() != "" && hist[8].ToString() != "" && hist[9].ToString() != "" && hist[10].ToString() != "" && hist[11].ToString() != "")
{
if (hist[11].ToString() != "")
{
if (hist[11].ToString() != val)
{
filas = dt.FORMULAHIST.NewRow();
filas["FECHA"] = hist[0].ToString();
filas["CEMENTO"] = hist[1].ToString();
filas["CARBONATO"] = hist[2].ToString();
filas["CELVIRGEN"] = hist[3].ToString();
filas["CELDKL"] = hist[4].ToString();
filas["PVA"] = hist[5].ToString();
filas["HIDRO"] = hist[6].ToString();
filas["LODO"] = hist[7].ToString();
filas["FIBER"] = hist[8].ToString();
filas["DESCCEL"] = hist[9].ToString();
filas["OTRO"] = hist[10].ToString();
filas["CODIGO"] = hist[11].ToString();
dt.FORMULAHIST.Rows.Add(filas);
exitval++;
}
val = hist[11].ToString();
}
}
}
con.CerrarConexion();
}