Aalhussein

Aalhussein

  • 1.5k
  • 133
  • 9.1k

connection string running out of connection pooling

Jan 23 2020 7:21 PM
Hi, I have a webform application, when I access the website, things works fine. but when multiple people access the site, it gives me a message that I have exceeded the connection pooling . 
I revised my code accessing the database with  the folling one. Still I am having same problem. Any idea how to prevent exceeling connection pool .
 
thanks for your support
  1. public static string conStr = WebConfigurationManager.ConnectionStrings["conStrKfmc"].ConnectionString;  
  2. public SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["conStrKfmc"].ConnectionString);  
  3. public DataSet getDataSetPassSql(string mySql)  
  4. {  
  5. DataSet ds;  
  6. using (SqlConnection cn = new SqlConnection(conStr))  
  7. {  
  8. using (SqlCommand cmd = new SqlCommand(mySql, cn))  
  9. {  
  10. SqlDataAdapter da = new SqlDataAdapter(cmd);  
  11. ds = new DataSet();  
  12. using (cn)  
  13. {  
  14. cn.Open();  
  15. da.Fill(ds);  
  16. return ds;  
  17. }  
  18. }  
  19. }  
  20. }  
  21. public int InsertUpdateDelete(string mySql, Dictionary myPara)  
  22. {  
  23. int rtn = 0;  
  24. using (SqlCommand cmd = new SqlCommand(mySql, con))  
  25. {  
  26. cmd.CommandType = CommandType.Text;  
  27. foreach (KeyValuePair p in myPara)  
  28. {  
  29. cmd.Parameters.AddWithValue(p.Key, p.Value);  
  30. }  
  31. using (con)  
  32. {  
  33. con.Open();  
  34. rtn = cmd.ExecuteNonQuery();  
  35. con.Close();  
  36. }  
  37. }  
  38. return rtn;  
  39. }   
Thanks for your support

Answers (3)