Sql-server – MS SQL ping external server

sql server

Is there a 'nice' way to check whether an network host is up
making use of 'plain' SQL? I thought of some MS-SQL specific
command or maybe some getting the return value from a ping script
on the server itself.

Does anyone has an idea on this?

Best Answer

There's two possible ways to take your answer: 1. you want to know if a SQL server is running on an arbitrary host
2. You want to ping an arbitrary host from a SQL server using some query.

  1. you could use dariom's answer. 1a. if you want to query one SQL server from another, you're better off using the "Linked Servers" functionality of SQL Server.

  2. You can use the master.dbo.xp_cmdshell stored procedure to execute PING, which then returns the results as text rows and a status code.

EXEC master.dbo.xp_cmdshell 'ping'