Announcement

Collapse
No announcement yet.

Check SQL server availability

Collapse

Ads on showthread pages

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Check SQL server availability

    WordPress Hosting on SSD Servers

    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
Sign up for a News Letter Click here to sign up