using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace MyKTV
{
class DBHelper
{
private string connstr = string.Format("Data Source=服务器名;Initial Catalog=MyKTV(数据库名);User ID=用户名;Pwd=密码");//如果是windows登陆就写(Integrated Security=True),服务器名本机可用(.)点,没有密码Pwd可以不写,
private SqlConnection connection;
public SqlConnection Connection
{
get
{
if (connection == null)
{
connection = new SqlConnection(connstr);
}
return connection;
}
}
public void OpenConnection()
{
if (Connection.State == ConnectionState.Closed)
{
Connection.Open();
}
else if (Connection.State == ConnectionState.Broken)
{
Connection.Close();
Connection.Open();
}
}
public void CloseConnection()
{
if (Connection.State == ConnectionState.Open || Connection.State == ConnectionState.Broken)
{
Connection.Close();
}
}
}
}
取消
评论