title: Dealing with huge amount of data when inserting into sql database
body: <p>in my code the user can upload an excel document wish contains it's phone contact list.Me as a developer should read that excel file turn it into a dataTable and insert it into the database .
  The Problem is that some clients have a huge amount of contacts like saying 5000 and more contacts and when i am trying to insert this amount of data into the database it's crashing and giving me a timeout exception.
  What would be the best way to avoid this kind of exception and is their any code that can reduce the time of the insert statement so the user don't wait too long ? </p>
  
  <p>the code </p>
  
  <pre><code>public SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  public void Insert(string InsertQuery)
  {
      SqlDataAdapter adp = new SqlDataAdapter();
      adp.InsertCommand = new SqlCommand(InsertQuery, connection);
      if (connection.State == System.Data.ConnectionState.Closed)
      {
          connection.Open();
      }
      adp.InsertCommand.ExecuteNonQuery();
      connection.Close();
  }
  
  protected void submit_Click(object sender, EventArgs e) 
  {
      string UploadFolder = "Savedfiles/";
      if (Upload.HasFile) {
          string fileName = Upload.PostedFile.FileName;
          string path=Server.MapPath(UploadFolder+fileName);
          Upload.SaveAs(path);
          Msg.Text = "successfully uploaded";
          DataTable ValuesDt = new DataTable();
          ValuesDt = ConvertExcelFileToDataTable(path);
          Session["valuesdt"] = ValuesDt;
          Excel_grd.DataSource = ValuesDt;
          Excel_grd.DataBind();
  
  
      }
  }
  
  protected void SendToServer_Click(object sender, EventArgs e)
  {
      DataTable Values = Session["valuesdt"] as DataTable ;
      if(Values.Rows.Count&gt;0)
      {
          DataTable dv = Values.DefaultView.ToTable(true, "Mobile1", "Mobile2", "Tel", "Category");
          double Mobile1,Mobile2,Tel;string Category="";
          for (int i = 0; i &lt; Values.Rows.Count; i++)
         {
              Mobile1 =Values.Rows[i]["Mobile1"].ToString()==""?0: double.Parse(Values.Rows[i]["Mobile1"].ToString());
              Mobile2 = Values.Rows[i]["Mobile2"].ToString() == "" ? 0 : double.Parse(Values.Rows[i]["Mobile2"].ToString());
              Tel = Values.Rows[i]["Tel"].ToString() == "" ? 0 : double.Parse(Values.Rows[i]["Tel"].ToString());
  
             Category = Values.Rows[i]["Category"].ToString();
             Insert("INSERT INTO client(Mobile1,Mobile2,Tel,Category) VALUES(" + Mobile1 + "," + Mobile2 + "," + Tel + ",'" + Category + "')");
             Msg.Text = "Submitied successfully to the server ";
         }
  
  
  
      }
  
  }
  </code></pre>