This C# function helps you check if SQL Server is running fine on a particular server and port. Useful to use on app startup, or for troubleshooting firewall problems after a Windows SP2 installation.
using System.Net;
using System.Net.Sockets;
public bool CheckSQLServer(string SQLHost, int SQLPort)
{
try
{
IPHostEntry IPHost = new IPHostEntry();
IPHost = Dns.Resolve(SQLHost);
IPAddress IPAddr = IPHost.AddressList[0];
TcpClient TcpCli = new TcpClient();
TcpCli.Connect(IPAddr, SQLPort);
TcpCli.Close();