• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to Register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

Check SQL server availability

Collapse

Unconfigured Ad Widget

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