资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

sqlserver查ip,sqlserver查询数据库

如何查看远程链接sqlserver的ip地址

可以使用存储过程和目录视图来管理链接服务器定义:

成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于做网站、网站建设、柘城网络推广、微信小程序开发、柘城网络营销、柘城企业策划、柘城品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供柘城建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com

# 通过执行 sp_addlinkedserver 创建链接服务器定义。

# 通过对 sys.servers 系统目录视图执行查询,查看有关在 SQL Server

的特定实例中定义的链接服务器的信息。

# 通过执行 sp_dropserver 删除链接服务器定义。还可以使用此存储过程删除远程服务器。

至于 sys.servers 视图的定义,可以查看 SQLServer 的帮助信息,内容比较多,还带表格,就不贴在这里了

sql server数据库ip地址怎么查

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_getlinkinfo]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[p_getlinkinfo] GO /*--获取连接SQL服务器的信息 所有连接本机的:操作的数据库名,计算机名,用户名,网卡物理地址,IP地址,程序名 --邹建2003.11(引用请保留此信息)--*/ /*--调用示例 --显示所有本机的连接信息 exec p_getlinkinfo --显示所有本机的连接信息,包含ip地址 exec p_getlinkinfo @includeip=1 --显示连接指定数据库的信息 exec p_getlinkinfo '客户资料' --*/ create proc p_getlinkinfo @dbname sysname=null,--要查询的数据库名,默认查询所有数据库的连接信息 @includeip bit=0--是否显示IP地址,因为查询IP地址比较费时,所以增加此控制 as declare @dbid int set @dbid=db_id(@dbname) create table #tb(id int identity(1,1),dbname sysname,hostname nchar(128),loginname nchar(128),net_address nchar(12),net_ip nvarchar(15),prog_name nchar(128)) insert into #tb(hostname,dbname,net_address,loginname,prog_name) select distinct hostname,db_name(dbid),net_address,loginame,program_name from master..sysprocesses where hostname'' and (@dbid is null or dbid=@dbid) if @includeip=0 goto lb_show  --如果不显示IP地址,就直接显示 declare @sql varchar(500),@hostname nchar(128),@id int create table #ip(hostname nchar(128),a varchar(200)) declare tb cursor local for select distinct hostname from #tb open tb fetch next from tb into @hostname while @@fetch_status=0 begin set @sql='ping '+@hostname+' -a -n 1 -l 1' insert #ip(a) exec master..xp_cmdshell @sql update #ip set hostname=@hostname where hostname is null fetch next from tb into @hostname end update #tb set net_ip=left(a,patindex('%:%',a)-1) from #tb a inner join ( select hostname,a=substring(a,patindex('Ping statistics for %:%',a)+20,20) from #ip where a like 'Ping statistics for %:%') b on a.hostname=b.hostname lb_show: select id,数据库名=dbname,客户机名=hostname,用户名=loginname ,网卡物理地址=net_address,IP地址=net_ip,应用程序名称=prog_name from #tb go

–2000 SQL code

select spid,hostname,net_address from sys.sysprocesses 

–2005 SQL code

select session_id,client_net_address,local_net_address from

sys.dm_exec_connections

如何获取IP地址 - SQL Server -

要获取数据库服务器IP,可通过xp_cmdshell 来获取信息,然后对信息进行筛选

xp_cmdshell 扩展存储过程将命令字符串作为操作系统命令 shell 执行,并以文本行的形式返回所有输出。由于存在安全隐患,所以在SQL Server 中, xp_cmdshell 默认是关闭的。

实现代码如下:

--开启xp_cmdshell

exec sp_configure 'show advanced options', 1

reconfigure with override

exec sp_configure 'xp_cmdshell', 1

reconfigure with override

exec sp_configure 'show advanced options', 0

reconfigure with override

go

begin

declare @ipline varchar(200)

declare @pos int

declare @ip varchar(40)

set nocount on

set @ip = null

if object_id('tempdb..#temp') is not null drop table #temp

create table #temp (ipline varchar(200))

insert #temp exec master..xp_cmdshell 'ipconfig'

select @ipline = ipline

from #temp

where upper (ipline) like '%IPv4 地址%'--这里需要注意一下,系统不同这里的匹配值就不同

if @ipline is not null

begin

set @pos = charindex (':',@ipline,1);

set @ip = rtrim(ltrim(substring (@ipline ,

@pos + 1 ,

len (@ipline) - @pos)))

end

select distinct(rtrim(ltrim(substring (@ipline ,

@pos + 1 ,

len (@ipline) - @pos)))) as ipaddress from #temp

drop table #temp

set nocount off

end

go


网站名称:sqlserver查ip,sqlserver查询数据库
文章路径:http://cdkjz.cn/article/dsipcij.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220