0

I have implemented a web application using asp.net MVC to convert excel file into .csv file.

Everything is working fine with small file.

But when I am trying to run larger file I was getting the error at client side "ERR_CONNECTION_RESET".

I have done R & D and have found the solution i.e

Even after same I have faced same issue. And then I have implemented threading by referring this Set Timeout For Controller Action.

Now I am getting the exception of "Thread is being aborted".

Here I have added my stack trace. Please help me to sort it out...

Exception: 'Thread was being aborted.' : 
StackTrace: 'at System.Data.Common.UnsafeNativeMethods.IRowset.GetData(IntPtr hRow, IntPtr hAccessor, IntPtr pData)
at System.Data.OleDb.OleDbDataReader.GetRowDataFromHandle()
at System.Data.OleDb.OleDbDataReader.GetValueBinding(MetaData info)
at System.Data.OleDb.OleDbDataReader.GetValues(Object[] values)
at  System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[] values)
at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at ExcelToCsvConversion.Controllers.HomeController.Check_In_Masters(String sourceFile, String worksheet2, Int32 colNo, String fieldValue)'

Here Is my code....

   public ActionResult ConvertToCsv(FileUpload model)
    {       
        var fileName = model.SourceFile;
        FileUpload fileUpload = new FileUpload();
        try
        {
            string filename = Path.GetFileName(model.SourceFile);
            model.SourceFile = Path.Combine(Server.MapPath("~/App_Data/uploads"), filename);

                model.WorkSheet1 = "Upload file$";

                System.Threading.Tasks.Task.Factory.StartNew(() => ConvertExcelToCSV_LT(model));

                fileUpload.SourceFile = filename;

        }
        catch (Exception e)
        {
            ServerExceptionLog(e);
        }

        return Json(new { filemodel = fileUpload }, JsonRequestBehavior.AllowGet);
    }
Community
  • 1
  • 1

3 Answers3

2

Have you tried playing with

<httpRuntime executionTimeout="HH:MM:SS" />

by default you're limited to 110 seconds.

Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89
1

Increase the upload size in web.config

<system.web>
  <httpRuntime maxRequestLength="2147483647" />
</system.web>

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->
    </requestFiltering>
  </security>
</system.webServer>

maxRequestLength is an Int32 (check here) so you can set the size accordingly.
maxAllowedContentLength is a uint (check here)

HCJ
  • 529
  • 1
  • 6
  • 14
0

Did you try it using TaskCreationOptions.LongRunning?

Task.Factory.StartNew(() => ConvertExcelToCSV_LT(model), 
    TaskCreationOptions.LongRunning);
Christoph Fink
  • 22,727
  • 9
  • 68
  • 113