数据库连接判断
public bool IsConnected()
{
SqlConnection connection = new SqlConnection(connectionString);//connectionString 数据库连接字符串
try
{
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
return true;
}
catch
{
return false;
}
}
{
SqlConnection connection = new SqlConnection(connectionString);//connectionString 数据库连接字符串
try
{
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
return true;
}
catch
{
return false;
}
}