国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
如何通過(guò)T-SQL獲得當(dāng)前連接的客戶端的IP和機(jī)器名

如何通過(guò)T-SQL獲得當(dāng)前連接的客戶端的IP和機(jī)器名

[日期:2005-07-08]來(lái)源:CSDN  作者:[字體: ]

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

    下面的SP是返回所有的客戶端的IP和HOSTNAME,目的是可以通過(guò)JOB返回某一時(shí)間點(diǎn)的CLIENT 的連接情況.

     我當(dāng)時(shí)寫(xiě)這個(gè)腳本的目的是經(jīng)常有一些沒(méi)有授權(quán)的客戶機(jī),通過(guò)SQLSERVER的CLIENT就連接到SQLSERVER,所以我可以定義一個(gè)JOB每隔30分鐘運(yùn)行一次這個(gè)存儲(chǔ)過(guò)程,并且將內(nèi)容寫(xiě)的一個(gè)LOG文件,這樣可以大概記錄有哪些CLIENT在連接SQLSERVER,當(dāng)然大家可以可以修改這個(gè)腳本,使之返回更多的信息,比如CPU,MEMORY,LOCK....

Author:黃山光明頂

mail:leimin@jxfw.com

version:1.0.0

date:2004-1-30

(如需轉(zhuǎn)載,請(qǐng)注明出處!)

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

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

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
在SQL Server服務(wù)器內(nèi)獲取客戶端的IP地址
SQL Server 2000基礎(chǔ)教程——字符串函數(shù)(二)
《SQL Server數(shù)據(jù)庫(kù)應(yīng)用開(kāi)發(fā)技術(shù)》第6章 數(shù)據(jù)完整性實(shí)施
asp.net中獲取客戶端ip地址的兩種方法
用PHP導(dǎo)出MySQL數(shù)據(jù)庫(kù)內(nèi)容為.sql文件
SQL SERVER 利用觸發(fā)器禁止刪除數(shù)據(jù)并記錄刪除日志
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服