D
D
denis_MInB2018-04-19 18:05:35
ASP.NET
denis_MInB, 2018-04-19 18:05:35

Upload 350000 rows to the server, how to do?

There is an ASP.NET MVC site hosted on reg.ru
, there is an Excel file at the input, the contents of the file must be loaded through the site into the database. There is a problem most likely with the connection timeout, "ERR_CONNECTION_RESET" appears - Unable to access the site. The file weighs 8MB, the number of records is 350,000. (It can be more than about 800 thousand).
In Web.config I currently have

<httpRuntime maxRequestLength="16384" executionTimeout="3600"/>

Download method:
[HttpPost]
    public ActionResult UploadLsGis(HttpPostedFileBase upload2)
    {            
        List<LsKvitGis> l = new List<LsKvitGis>();
        if (upload2 != null && upload2.ContentLength > 0)
        {
            int SN = 1;
            var fileName = Path.GetFileName(upload2.FileName);
            var path = Path.Combine(Server.MapPath("~/App_Data/Files"), fileName);
            upload2.SaveAs(path);
            using (XLWorkbook workBook = new XLWorkbook(path))
            {
                var ws = workBook.Worksheet(1);
                int lastrow = ws.LastCellUsed().Address.RowNumber;
                while (SN<=lastrow)
                {                        
                    l.Add(new LsKvitGis {
                        LS = ws.Row(SN).Cell(1).Value.ToString(),
                        LSGis = ws.Row(SN).Cell(2).Value.ToString()
                    });
                    SN++;
                }
            }
            db.lsKvitGiss.RemoveRange(from s in db.lsKvitGiss select s); //удаляю что было раньше
            db.lsKvitGiss.AddRange(l); // добавляю
            db.SaveChanges(); // сохраняю
            ViewBag.Message = "Файл с ЛС ГИС загружен";
        }
        return View("Index");
    }

On localhost, the entire file is loaded without problems. In production, small files are loaded (3800 lines loaded), large ones are not loaded.
I found out that the hoster is limiting resources (the support service sent logs, I really saw that it was crashing both on the CPU and on the OP)
.
Perhaps there are thoughts?
Of course, you can beat the files into smaller ones on the user's side, but this is also not an option, the customer does not want to agree to this. If you hit while loading...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fat Lorrie, 2018-04-19
@Free_ze

You can try to split the file into chunks and send them in stages with different requests.

M
mindgrow, 2018-04-21
@mindgrow

Attach WebAPI to your server and pass data line by line via Json/XML

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question