日期:2014-05-16 浏览次数:20585 次
//定义数据库链接属性
private static SqlConnection objSqlConnection;
/// <summary>
/// 获得数据库连接状态
/// </summary>
public static SqlConnection ObjSqlConnection
{
get
{
string DBConnectionString = ConfigurationManager.ConnectionStrings["NopSqlConnection"].ConnectionString;
if (objSqlConnection == null)
{
objSqlConnection = new SqlConnection(DBConnectionString);
objSqlConnection.Open();
}
else if (objSqlConnection.State == System.Data.ConnectionState.Closed)
{
objSqlConnection.Open();
}
else if (objSqlConnection.State == System.Data.ConnectionState.Broken)
{
objSqlConnection.Close();
objSqlConnection.Open();
}
return objSqlConnection;
}
}
public static void CloseConn()
{
if (objSqlConnection.State == ConnectionState.Open)
{
objSqlConnection.Close();
}