Check SQL server availability

Collapse

Unconfigured Ad Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Manuel_
    Banned
    • May 2005
    • 120

    Check SQL server availability


    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();

    return true;
    }
    catch
    {
    return false;
    }
    }
Working...
X