数据库中测试网络是否连通

sxlcom 2006-02-26 04:40:00
create table #temp (mystr varchar(200))
declare @netok int
insert into #temp exec xp_cmdshell 'ping IP'
select @netok=count(*) from #temp where mystr like 'Request timed out%'
if @netok>2
print '网络不通'
else
print '网络OK'
drop table #temp
提示:能找到存储过程 'xp_cmdshell'。
怎么解决
...全文
204 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
samfeng_2003 2006-02-26
  • 打赏
  • 举报
回复
create proc p_ping
@ip varchar(20),
@message int output
as
begin
create table #(col varchar(8000))
declare @sql varchar(8000)
set @sql='insert # exec master..xp_cmdshell ''ping '+@ip+''''
exec(@sql)

if exists (select * from # where col like '%Request timed out%')
set @message=0
else
set @message=1
drop table #
end
go

declare @message int
exec dbo.p_ping '127.0.0.1',@message output

if @message=0
print '网络不通'
else
print '网络ok'

exec dbo.p_ping '192.168.0.1',@message output

if @message=0
print '网络不通'
else
print '网络ok'

drop proc p_ping


(所影响的行数为 13 行)

网络ok

(所影响的行数为 13 行)

网络不通

22,302

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧