查詢目前連線的客戶端的相關資訊

2021-08-17 21:59:07 字數 2625 閱讀 1924

--查詢目前連線的客戶端的相關資訊

select c.local_net_address as sqlserverip,

c.client_net_address as clientip,

c.client_tcp_port as clienttcpport,

c.session_id as sessionid,

s.program_name as programname,

s.loginame as loginname

from sys.dm_exec_connections as c

inner join sys.sysprocesses s

on c.session_id = s.spid

where session_id = @@spid

--用觸發器實現刪除監控

use tempdb

goif exists(select * from sys.triggers as t where t.name='trig_t_d')

begin

drop trigger trig_t_d

endgo

--測試表

if object_id('t') is not null drop table t

--日誌表

if object_id('[log_data]') is not null drop table [log_data]

gocreate table t(id int identity(1,1) primary key,n nvarchar(10))

create table log_data(

logid int identity(1,1) primary key

,sqlserverip varchar(20)

,clientip varchar(20)

,clienttcpport varchar(20)

,sessionid varchar(20)

,programname varchar(200)

,loginname varchar(50)

,exectime datetime not null default(getdate()) )go

insert into t(n)

select left(newid(),10) from master.dbo.spt_values as sv where sv.[type]='p' and sv.number between 1 and 1000

gocreate trigger trig_t_d

on t

after delete

asbegin

if (select count(1) from deleted)>1

begin

raiserror('不允許刪除多條資料!',18,1)

rollback tran;

return;

endelse

begin

set nocount on

insert into log_data

( -- logid -- this column value is auto-generated

sqlserverip,

clientip,

clienttcpport,

sessionid,

programname,

loginname

) select

local_net_address as sqlserverip

,client_net_address as clientip

,c.client_tcp_port as clienttcpport

,c.session_id as sessionid

,s.program_name as programname

,s.loginame as loginname

from sys.dm_exec_connections c

inner join sys.sysprocesses s on c.session_id=s.spid

where session_id = @@spid

set nocount off

endendgo

--測試刪除10條記錄

set rowcount 10

delete from t

set rowcount 0

/*訊息 3609,級別 16,狀態 1,第 34 行

事務在觸發器中結束。批處理已中止。

訊息 50000,級別 18,狀態 1,過程 trig_t_d,第 40 行

不允許刪除多條資料!

*/go

--測試刪除1條記錄

set rowcount 1

delete from t

set rowcount 0

/*(1 行受影響)

*/--檢視執行了刪除記錄的詳細情況。

--主要是 clientip, programename, loginname, exectime

select * from log_data

IMSHello客戶端的相關資訊

客戶端設定資訊 包括p cscf位址,p cscf埠,網域名稱,impu,impi package org.imshello.ngn.utils.ngnconfigurationentry 客戶端由org.imshello.droid.main啟動,啟動之後startactivityforresul...

獲得客戶端的資訊

獲得客戶端的資訊 記得datasnap 2009時,要得到客戶端資訊,非官方的方法,要去搞什麼dsconnecteventobject.channelinfo.id,弄成 tidtcpconnection。xe2就好得多了。仍然是在dsserver的onconnect 事件裡,dsconnectev...

關於客戶端資訊的獲取

request.servervariables url 返回伺服器位址 request.servervariables path info 客戶端提供的路徑資訊 與應用程式元資料庫路徑相應的物理路徑 request.servervariables path translated 通過由虛擬至物理的對...