高手指点:数据库的连接字符串封装类是静态化好还是实例化好?
本帖最后由 angkor506 于 2013-06-29 17:30:14 编辑
希望高手指点:封装数据库的连接字符串是静态化好还是实例化好?哪个运行的效率高而且能把应用池尽快释放处理? 现在是实例化的:
namespace WebConn
{
#region 数据库操作类
public class B_SqlConn : IDisposable
{
public SqlConnection Conn = null;
public string strConn = System.Configuration.ConfigurationManager.AppSettings["StrConn"];
/// <summary>
/// 打开数据库连接
/// </summary>
public void Open()
{
Conn = new SqlConnection(strConn);
if (Conn.State == ConnectionState.Closed)
{
Conn.Open();
}
else if (Conn.State == ConnectionState.Broken)
{
Conn.Close();
Conn.Open();
}
}
/// <summary>
/// 关闭数据库连接
/// </summary>
public void Close()
{
Conn = new SqlConnection(strConn);
if (Conn.State == ConnectionState.Open)//判断连接的状态是否打开
{
Conn.Close();
}