title: Import large amounts of data from Excel file into SQL Server using .NET Core and Angular
body: <p>I want to import data from Excel files into SQL Server. The size of the file is 22 MB and contains approximately 1 million rows, but I get the error timeout.</p>
  <p>This is the code of my controller</p>
  <pre><code>[System.Web.Http.Route(&quot;UploadExcel&quot;)]
  [System.Web.Http.HttpPost]
  [RequestFormLimits(MultipartBodyLengthLimit = 409715200)]
  [RequestSizeLimit(409715200)]
  public string ExcelUpload()
  {
          string message = &quot;&quot;;
          HttpResponseMessage result = null;
          var httpRequest = HttpContext.Current.Request;
  
          using (AngularDBEntities objEntity = new AngularDBEntities())
          {
              if (httpRequest.Files.Count &gt; 0)
              {
                  HttpPostedFile file = httpRequest.Files[0];
                  Stream stream = file.InputStream;
  
                  IExcelDataReader reader = null;
  
                  if (file.FileName.EndsWith(&quot;.xls&quot;))
                  {
                      reader = ExcelReaderFactory.CreateBinaryReader(stream);
                  }
                  else if (file.FileName.EndsWith(&quot;.xlsx&quot;))
                  {
                      reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                  }
                  else
                  {
                      message = &quot;This file format is not supported&quot;;
                  }
  
                  DataSet excelRecords = reader.AsDataSet();
                  reader.Close();
  
                  var finalRecords = excelRecords.Tables[0];
  
                  for (int i = 0; i &lt; finalRecords.Rows.Count; i++)
                  {
                      UserDetail objUser = new UserDetail();
                      objUser.UserName = finalRecords.Rows[i][0].ToString();
                      objUser.EmailId = finalRecords.Rows[i][1].ToString();
                      objUser.Gender = finalRecords.Rows[i][2].ToString();
                      objUser.Address = finalRecords.Rows[i][3].ToString();
                      objUser.MobileNo = finalRecords.Rows[i][4].ToString();
                      objUser.PinCode = finalRecords.Rows[i][5].ToString();
  
                      objEntity.UserDetails.Add(objUser);
                  }
  
                  int output = objEntity.SaveChanges();
  
                  if (output &gt; 0)
                  {
                      message = &quot;Excel file has been successfully uploaded&quot;;
                  }
                  else
                  {
                      message = &quot;Excel file uploaded failed&quot;;
                  }
              }
              else
              {
                  result = Request.CreateResponse(HttpStatusCode.BadRequest);
              }
          }
  
          return message;
      }
  </code></pre>
  <p>I added <code>maxRequestLength=&quot;1048576&quot; executionTimeout=&quot;999999&quot;</code> to the <code>web.config</code> file in the <code>system.web</code> section, and <code>maxAllowedContentLength=&quot;1073741824&quot;</code> to security tag, but I am still facing this problem.</p>
  <p>Knowing that when I upload small files, the data is added to the table</p>