你的主机屋数据库是怎么连接上去的,我尝试了好多方法一直都是not alllow to connect
1个回答
展开全部
private static String _strConn = "server=.;uid=sa;pwd=sa;database=dbname";
private static SqlConnection _dbConn = new SqlConnection(_strConn);
public static SqlConnection getConnection()
{
if (_dbConn == null)
{
_dbConn = new SqlConnection(_strConn);
_dbConn.Open();
}
else if (_dbConn.State == ConnectionState.Closed || _dbConn.State == ConnectionState.Broken)
{
_dbConn.Close();
_dbConn.ConnectionString = _strConn;
_dbConn.Open();
}
return _dbConn;
}
private static SqlConnection _dbConn = new SqlConnection(_strConn);
public static SqlConnection getConnection()
{
if (_dbConn == null)
{
_dbConn = new SqlConnection(_strConn);
_dbConn.Open();
}
else if (_dbConn.State == ConnectionState.Closed || _dbConn.State == ConnectionState.Broken)
{
_dbConn.Close();
_dbConn.ConnectionString = _strConn;
_dbConn.Open();
}
return _dbConn;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询