用户操作
[即时聊天] [发私信] [加为好友]
黄山光明顶ID:leimin
37549次访问,排名3196(-1),好友1人,关注者16人。
System integration Service. SQL Server DBA, Retail Consultant.
leimin的文章
原创 26 篇
翻译 1 篇
转载 13 篇
评论 14 篇
黄山光明顶的公告
今天更换一下首页的风格,希望心情也随着更换 :-)
最近评论
mldstk:wow gold,
monarch10:的确非常的好,不过想知道是怎么实现的.
诚邀加入我们的it优秀博客荟萃:您好,我们网站要做一个it优秀博客的荟萃栏目,诚邀您加入,我们会将您的博客名称和网址加入到我们的博客荟萃栏目中,并请将我们的网址:http://www.51ui.cn (北京创享数码)链接在您的博客中。如同意请回复邮件:jacky@51ui.cn来信请将您的博客名和链接网址写明,以便我们添加您的链接。

我们的网站介绍:
我们是北京专业从事ui界面开发的设计类网站,在……
高手:sqlserver 2005已经支持rownum
一个between and + rownum就搞分页
没有任何代码侵入。
王东祥:很好 就是不明白 啊
文章分类
收藏
相册
Auchan 2005 Seminar
France 2005
公司团队
皖南游
Database
Engine Watch(RSS)
SQL Server Center
SQL SERVER Magzine
MS .NET
『 天道酬勤 』(RSS)
21世纪.NET(RSS)
Developer Center
Realize .NET Potential(RSS)
博客堂(RSS)
思归's Blog(RSS)
怡红公子(RSS)
破宝BLOG(RSS)
老赵BLOG(RSS)
讲武堂-Jiangtao(RSS)
Others
Felix的技术专栏(CommunityServer)(RSS)
TestWin 软件测试之窗(RSS)
蓝法典的专栏(RSS)
存档
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes

原创 如何通过T-SQL获得当前连接的客户端的IP和机器名收藏

新一篇: 修复SQLSERVER2000数据库之实战经验 | 旧一篇: 一句T-SQL语句引发的思考

/*****************************************************************************************************************

    下面的SP是返回所有的客户端的IP和HOSTNAME,目的是可以通过JOB返回某一时间点的CLIENT 的连接情况.

     我当时写这个脚本的目的是经常有一些没有授权的客户机,通过SQLSERVER的CLIENT就连接到SQLSERVER,所以我可以定义一个JOB每隔30分钟运行一次这个存储过程,并且将内容写的一个LOG文件,这样可以大概记录有哪些CLIENT在连接SQLSERVER,当然大家可以可以修改这个脚本,使之返回更多的信息,比如CPU,MEMORY,LOCK....

Author:黄山光明顶

mail:leimin@jxfw.com

version:1.0.0

date:2004-1-30

(如需转载,请注明出处!)

*********************************************************************************************************/

Create proc usp_getClient_infor
as
set nocount on

Declare @rc int
Declare @RowCount int

Select @rc=0
Select @RowCount=0

begin
--//create temp table ,save sp_who information
  create table #tspid(
 spid int null,
 ecid int null,
 status nchar(60) null,
 loginname nchar(256) null,
 hostname nchar(256) null,
 blk bit null,
 dbname nchar(256) null,
 cmd nchar(32)
  )

--//create temp table save all SQL client IP and hostname and login time
Create table #userip(
 [id]int identity(1,1),
 txt varchar(1000),
)

--//Create result table to return recordset
Create table #result(
 [id]int identity(1,1),
 ClientIP varchar(1000),
 hostname nchar(256),
 login_time datetime default(getdate())

 )
--//get host name by exec sp_who ,insert #tspid from sp_who,
insert into #tspid(spid,ecid,status,loginname,hostname,blk,dbname,cmd) exec sp_who

declare @cmdStr varchar(100),
 @hostName nchar(256),
 @userip varchar(20),
 @sendstr varchar(100)
 

--//declare a cursor from table #tspid
declare tspid cursor
for select distinct hostname from #tspid  with (nolock) where spid>50
for read only

open tspid
   fetch next from tspid into @hostname
   While @@FETCH_STATUS = 0
   begin
 select @cmdStr='ping '+rtrim(@hostName)
 
 insert into #userip(txt) exec master..xp_cmdshell @cmdStr
 
 select @rowcount=count(id) from #userIP


 if @RowCount=2 --//no IP feedback package
  begin
  insert into #Result(ClientIP,hostname) values('Can not get feedback package from Ping!',@hostname)
  end
 if @RowCount>2 
  begin
  select @userip=substring(txt,charindex('[',txt)+1,charindex(']',txt)-charindex('[',txt)-1)
  from #userIP
  where txt like 'Pinging%'
  
  insert into #Result(ClientIP,hostname) values(@userIP,@hostname)
  end
 select @rc=@@error
 if @rc=0
  truncate table #userip --//clear #userIP table

   fetch next from tspid into @hostname
 end

close tspid
deallocate tspid

select * from #result with(nolock)

drop table #tspid
drop table #userip
drop table #result
end
go
exec usp_getClient_infor

发表于 @ 2004年02月09日 00:07:00|评论(loading...)|编辑

新一篇: 修复SQLSERVER2000数据库之实战经验 | 旧一篇: 一句T-SQL语句引发的思考

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © 黄山光明顶