发布网友 发布时间:2024-10-21 15:47
共1个回答
热心网友 时间:8分钟前
//连接对象
private static SqlConnection conn;
public static SqlConnection Conn
{
get
{
//从表示层的web.config中获取连接字符串
string str = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString.ToString();
if (conn == null)
{
conn = new SqlConnection(str);
conn.Open();
}
else if (conn.State == System.Data.ConnectionState.Closed)
{
conn.Open();
}
else if (conn.State == System.Data.ConnectionState.Broken)
{
conn.Close();
conn.Open();
}
return conn;
}
}