;
   3:  
   4: private void button1_Click(object sender, EventArgs e)
   5: {
   6:     
   7:  
   8:     int count = 50;
   9:  
  10:     DateTime start = DateTime.Now;
  11:     for (int i = 0; i < count; i++)
  12:     {
  13:         using (SqlConnection conn = new SqlConnection(connStringUsePool))
  14:         {
  15:             conn.Open();
  16:             conn.Close();
  17:         }
  18:     }
  19:     DateTime end = DateTime.Now;
  20:     TimeSpan ts = end - start;
  21:     label1.Text = "使用连接池"+ts.Milliseconds.ToString();
  22:  
  23:     start = DateTime.Now;
  24:     for (int i = 0; i < count; i++)
  25:     {
  26:         using (SqlConnection conn = new SqlConnection(connStringUnUsePool))
  27:         {
  28:             conn.Open();
  29:             conn.Close();
  30:         }
  31:     }
  32:     end = DateTime.Now;
  33:     ts = end - start;
  34:     label2.Text = "不使用连接池" + ts.Milliseconds.ToString();
  35: }
;
   3:  
   4: private void button1_Click(object sender, EventArgs e)
   5: {
   6:     
   7:  
   8:     int count = 50;
   9:  
  10:     DateTime start = DateTime.Now;
  11:     for (int i = 0; i < count; i++)
  12:     {
  13:         using (SqlConnection conn = new SqlConnection(connStringUsePool))
  14:         {
  15:             conn.Open();
  16:             conn.Close();
  17:         }
  18:     }
  19:     DateTime end = DateTime.Now;
  20:     TimeSpan ts = end - start;
  21:     label1.Text = "使用连接池"+ts.Milliseconds.ToString();
  22:  
  23:     start = DateTime.Now;
  24:     for (int i = 0; i < count; i++)
  25:     {
  26:         using (SqlConnection conn = new SqlConnection(connStringUnUsePool))
  27:         {
  28:             conn.Open();
  29:             conn.Close();
  30:         }
  31:     }
  32:     end = DateTime.Now;
  33:     ts = end - start;
  34:     label2.Text = "不使用连接池" + ts.Milliseconds.ToString();
  35: }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
  • 2021-09-16
猜你喜欢
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
  • 2022-02-27
  • 2022-02-10
相关资源
相似解决方案