标签:nbsp reading nstat ext client orm int new using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace TicketSystem
{
public class DBHelper
{
string conStr = "Data Source=.;Initial Catalog=Ticket;Integrated Security=True";
private SqlConnection _connection;
/// <summary>
/// 公共属性,获取连接对象
/// </summary>
public SqlConnection Connection {
get{
if(_connection==null){
_connection=new SqlConnection(conStr);
}
return _connection;
}
}
/// <summary>
/// 打开数据库连接
/// </summary>
public void OpenConnect() {
if (_connection.State == ConnectionState.Closed)//关闭状态
{
_connection.Open();
}
else if (_connection.State == ConnectionState.Broken)//断开状态
{
_connection.Close();
_connection.Open();
}
}
/// <summary>
/// 关闭数据库连接
/// </summary>
public void CloseConnect() {
if (_connection.State == ConnectionState.Open
|| _connection.State == ConnectionState.Broken)
{
_connection.Close();
}
}
}
}
标签:nbsp reading nstat ext client orm int new using
原文地址:http://www.cnblogs.com/a1111/p/6041098.html