图片的提示就是“超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小”
知道是某个数据没关闭,可是我在很多地方加了close还是不行 有些地方加了会提示检测到无法访问代码,鼠标移到ExecuteReader会提示System.InvalidOperationException System.Data.SqlClient.SqlException异常的信息。
代码:
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient;
public class dataOperate{ public SqlConnection con; public dataOperate() { } public bool execSQL(string sql) { SqlConnection con = createCon(); con.Open(); SqlCommand com = new SqlCommand(sql, con); try { com.ExecuteNonQuery(); con.Close(); } catch (Exception e) { con.Close(); return false; } return true; } public int seleSQL(string sql) { SqlConnection con = createCon(); con.Open(); SqlCommand com = new SqlCommand(sql, con); try { return Convert.ToInt32(com.ExecuteScalar()); } catch (Exception e) { CloseDB(); return 0; } } public DataSet getDataset(string sql, string table) { using (SqlConnection con = createCon()) { con.Open(); DataSet ds; SqlDataAdapter sda = new SqlDataAdapter(sql, con); ds = new DataSet(); sda.Fill(ds, table); return ds; } } public SqlDataReader ExceRead(string sql) { SqlConnection con = createCon(); con.Open(); SqlCommand com = new SqlCommand(sql, con); SqlDataReader read = com.ExecuteReader(); return read; } public SqlConnection createCon() { con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStr"].ToString()); return con; } public void CloseDB() { if (con.State == ConnectionState.Open) { con.Close(); } }}
我在web.configl里加了个
如果在这里加个Max Pool Size=512 这样治标不治本而且会损坏系统性能 请问有什么好的方法吗