2

I've developed an ASP.NET application that receives input from the user which is basically an SQL query ran by LogParser. (This input is kept in the "sql1" string. It works, but works slowly. For a log file of 60 MB, I've even received an outofmemory exception. I'm sharing my code down below, any ideas to speed this up? Is there a way to directly insert the ILogRecordSet object to a DataGrid, without first converting it to a DataSet?

            LogQuery oLogQuery = new LogQuery();
            COMIISW3CInputFormat eventLog = new COMIISW3CInputFormat();

            ILogRecord numReq = null;
            ILogRecordSet numSet = null;

            numSet = oLogQuery.Execute(sql1, eventLog);
            DataTable queryTable = new DataTable("Query");
            for (int i = 0; i < numSet.getColumnCount(); i++)
            {
                DataColumn col = new DataColumn();
                col.ColumnName = numSet.getColumnName(i);
                switch (numSet.getColumnType(i))
                {
                    case 1:
                        col.DataType = Type.GetType("System.Int32");
                        break;
                    case 2:
                        col.DataType = Type.GetType("System.Double");
                        break;
                    case 4:
                        col.DataType = Type.GetType("System.DateTime");
                        break;
                    default:
                        col.DataType = Type.GetType("System.String");
                        break;
                }
                queryTable.Columns.Add(col);
            }

            while (!numSet.atEnd())
            {
                numReq = numSet.getRecord();
                DataRow row = queryTable.NewRow();

                for (int i = 0; i < numSet.getColumnCount(); i++)
                    row[i] = HttppUtility.HtmlEncode(Convert.ToString(numReq.getValue(i)));

                queryTable.Rows.Add(row);
                numSet.moveNext();
            }

            DataSet ds = new DataSet();
            ds.Tables.Add(queryTable);

            QueryGrid.DataSource = ds;
            QueryGrid.DataBind();
Slethron
  • 143
  • 1
  • 4
  • 11
  • You're building the full dataset in memory. I must admit I can't imagine it can fill memory for a 50 MB log file! Did you try to use ILogRecordSet as data source? At least with a wrapper class to "tunnel" data reading – Adriano Repetti Mar 08 '12 at 09:29
  • I've tried to use the ILogRecordSet object directly as data source, but it failed. I don't know about wrapper classes, can you enlighten me further? – Slethron Mar 09 '12 at 08:20
  • Pretty tedious code to write but I _guess_ you may start from here: http://blog.falafel.com/Blogs/AdamAnderson/07-01-30/Create_a_Custom_DataSource_Quickly_Easily_with_C_2_0_Iterators.aspx – Adriano Repetti Mar 09 '12 at 08:31
  • You'll get a couple of % speed improvement by caching getColumnCount() since that is being read each time a row is processed but it's value is always the same – Matthew Lock Jan 15 '15 at 00:55

0 Answers0