请帮忙看看这个问题怎么解决,来者有分!

paladins 2005-01-17 09:56:39
请问怎样在程序中得到周围所有运行ms-sql的server的主机名?
就像配置odbc数据源的时候,点击下拉菜单,可以显示所有附近sql主机。
...全文
132 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
kirao 2005-01-18
  • 打赏
  • 举报
回复
我想port檢查是一個方法,其它我只能幫助頂了!
Softlee81307 2005-01-18
  • 打赏
  • 举报
回复
帮顶
paladins 2005-01-18
  • 打赏
  • 举报
回复
难道要把局域网内所有主机都检查一遍?
qixiao 2005-01-17
  • 打赏
  • 举报
回复
我见过的好多sqlserver都不是默认的1433
up
didoleo 2005-01-17
  • 打赏
  • 举报
回复
怎么样识别一台主机上运行的是SQL SERVER 服务呢?,我想 SQL SERVER 默认的是1433端口,(可惜这个端口是可以任意改变的,只要不和系统端口冲突),假设端口没被改过,那么还有可能通过socket监听端口,看对方有没回应来取得主机器的ip或是机器名.但是要端口改掉了,我就不知道怎么办了.

看看下面的怎么回答吧?
Andy__Huang 2005-01-17
  • 打赏
  • 举报
回复
1,exec master..xp_cmdshell'osql -L'


2,或者
declare @cmdStr varchar(100)
create table #table(id int identity,txt varchar(1000))
create table #t(hostname varchar(100), ip varchar(100))
declare @id int
declare @hostname varchar(100)
set @id = 50
set nocount on
while exists (select top 1 HostName from master..sysprocesses where spid > @id)
begin
select top 1 @cmdStr='ping '+HostName, @id = spid, @hostname = hostname from master..sysprocesses where spid > @id order by spid
insert into #table(txt) exec master..xp_cmdshell @cmdStr
insert #T select @hostname, substring(txt,charindex('[',txt)+1,charindex(']',txt)-charindex('[',txt)-1) from #table where id=2
truncate table #table
end
set nocount off
select distinct * from #t
drop table #table
drop table #t
NinGoo 2005-01-17
  • 打赏
  • 举报
回复
帮顶

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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