让每个页面的生命周期过程只产生一个Connection连接
让每个页面的生命周期过程只产生一个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();
}
}