让每个页面的生命周期过程只产生一个Connection连接
页面基类代码如下:

public partial class BasePage : System.Web.UI.Page
{
    private SqlConnection _SqlConn;

    public  SqlConnection SqlConn
    {
        get
        {
            if (this._SqlConn == null)
            {
                this._SqlConn = new SqlConnection("connectionString");
                this._SqlConn.Open();                
            }
           return this._SqlConn;
        }       
    }

   

    public override void Dispose()
    {
        if (this.SqlConn.State != ConnectionState.Closed)
        {
            this.SqlConn.Close();
        }
        this.SqlConn.Dispose();
        base.Dispose();
    }
}

相关文章:

  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2021-12-13
  • 2021-09-04
  • 2021-10-27
猜你喜欢
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2021-09-11
  • 2021-06-26
相关资源
相似解决方案