12 May 2006
Detect SQL Server Availability
Posted by Mikhail Esteves under: C#; Tips .
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; } }
csharp, aspnet, code, tips, sql+server, sql, microsoft, sp2 2 Comments so far...
Dan Says:
25 May 2006 at 11:58 pm.
Pray that there isn’t a firewall and that you know the target SQL server’s port.
sam Says:
28 September 2006 at 4:36 pm.
install SP4 for SQL Server 2000
Firewall issue will be solved, it is running on port 1433