Add this simple function and use to check
public static bool GetConnectionState()
{
try
{
using (SqlConnection con = new SqlConnection(YOUR_SQLCONNECTION_STRING) //Set your connection string here
{
con.Open();
return (con.State == ConnectionState.Open);
}
}
catch (SqlException)
{
return false;
}
catch (Exception ex)
{
return false;
}
}