We can ping server from SQL Server in other word we can check current
status of linked server.I have tried to write a T-SQL for this.
DECLARE @ServerStatus TABLE(IPStaus VARCHAR(500))DECLARE @PingIP varchar(1000)SELECT @PingIP = 'ping ' + 'xx.xx.xx.xx'SET NOCOUNT ON;INSERT INTO @ServerStatusEXEC master.dbo.xp_cmdshell @PingIPIF EXISTS (SELECT 1 FROM @ServerStatus WHERE IPStaus LIKE '%Request timed out%' )BEGINPRINT 'Server does not exist'ENDELSEBEGINPRINT 'Server available.'END
That’s It
Enjoy Learning.
No comments:
Post a Comment