惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
P
Privacy International News Feed
Security Latest
Security Latest
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Last Watchdog
The Last Watchdog
S
Schneier on Security
Engineering at Meta
Engineering at Meta
Google Online Security Blog
Google Online Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
Cyberwarzone
Cyberwarzone
C
Cyber Attacks, Cyber Crime and Cyber Security
G
GRAHAM CLULEY
A
Arctic Wolf
博客园 - 聂微东
I
Intezer
腾讯CDC
罗磊的独立博客
T
Tailwind CSS Blog
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
L
Lohrmann on Cybersecurity
人人都是产品经理
人人都是产品经理
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
P
Palo Alto Networks Blog
Simon Willison's Weblog
Simon Willison's Weblog
W
WeLiveSecurity
N
News and Events Feed by Topic
SecWiki News
SecWiki News
S
Security Affairs
T
Threat Research - Cisco Blogs
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
T
Troy Hunt's Blog
N
News and Events Feed by Topic
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
酷 壳 – CoolShell
酷 壳 – CoolShell
M
MIT News - Artificial intelligence
I
InfoQ
Hacker News: Ask HN
Hacker News: Ask HN
T
The Blog of Author Tim Ferriss
Schneier on Security
Schneier on Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
Vercel News
Vercel News
博客园 - 三生石上(FineUI控件)
D
Darknet – Hacking Tools, Hacker News & Cyber Security

博客园 - yi

Rabbitmq的使用及Web监控工具使用 Fiddler的配置 轻松实现SQL Server与Access、Excel数据表间的导入导出 Sql server性能优化白皮书 索引的优化脚本 查找当前的登录用户 usp_who5脚本,查找当前的进程 linq to sql的性能和reader相比只是差一点点吗 锁与索引 一个数据访问层的小工具 转:对XML插入操作 - yi - 博客园 对数据的分页再一次思考 关注商业价值 应用程序优化 关于异常处理的一点看法 骂的人多了,也成了真理 样式小记 - yi - 博客园 重命名你的数据库 不浪费自己的时间,同时也不浪费别人的时间 - yi - 博客园
查看当前的连接和锁
yi · 2010-05-20 · via 博客园 - yi

本文来自:http://www.sqlservercentral.com/scripts/sp_who2/67351/

这个存储过程使用xsp_cmdshell得到IP地址,它取决于进程的数量而影响执行快慢

用法如下:exec usp_GetConnectionInfo

Create Proc usp_GetConnectionInfo
AS
Begin
    Declare @spid int,@ClientIPAddress varchar(500),@cmd varchar(260),@HostName varchar(100),@sqltext varchar(max)
    Declare @Lock_Info Table
        ( spid int,dbid int,objid int,indid int,locktype varchar(20),
            Resource varchar(100),Mode varchar(15),lockstatus varchar(100)
        )

    Declare @Process_Info Table
        ( spid int,proc_status varchar(10),Login_user varchar(100),HostName varchar(100),BlkBy char(10),DBname varchar(100),command varchar(200),
            CPUtime    int,diskio int,lastbatch varchar(100),programname varchar(250),spid_1 int,requestid int
        )
        
    Declare @All_Info Table
        ( spid int,Sql_Statement varchar(max),HostName varchar(50),HostIP varchar(100),Dbname varchar(100),ObjName varchar(100),Index_Type varchar(50),
            Lock_Type varchar(10),Lock_Mode varchar(10),Lock_Status varchar(50),BlockedBy char(10),Cputime int,
            DiskIO int,programname varchar(100),lastbatch varchar(100)
        )

    Insert into @Lock_Info
    Exec sp_lock
        
    Insert into @Process_Info    
    Exec sp_who2
    
    Declare mycur CURSOR
    FOR
    select spid,hostname from @Process_Info
    
    Declare @Results TABLE
     (
        Results varchar(500)
     )        
    
    create table #sqlstatement(eventtype varchar(100),parameters int,sqlstatement varchar(max))
    
        
    OPEN mycur
        fetch next from mycur into @spid,@HostName
        
        while(@@fetch_status=0)
        
        BEGIN
            insert into #sqlstatement
            EXEC ('DBCC Inputbuffer (' + @spid + ')')
            select @sqltext=sqlstatement from #sqlstatement
            truncate table #sqlstatement
            SET @cmd = 'ping ' + @HostName
            INSERT INTO @Results
            execute master..xp_cmdshell @cmd
            SELECT @ClientIPAddress=Replace(Left(Results, CharIndex(']', Results)), 'Pinging ', '')
            FROM @Results    WHERE Results LIKE 'Pinging%'
            
            Insert into @All_Info
            select p.spid,@sqltext,@hostname,@ClientIPAddress,p.dbname,object_Name(l.objid),    
            CASE indid When 0 Then 'HEAP'
                     When 1 Then 'CLUSTERED'
                     Else 'NON-CLUSTERED'
            END,l.locktype,l.Mode,l.lockstatus,p.blkby,p.CPUtime,p.diskio,p.programname,p.lastbatch    
            from @Lock_Info l right join @Process_Info p on l.spid=p.spid where p.spid=@spid
            and p.hostname not like '%.%'    
            fetch next from mycur into @spid,@HostName
    END

drop table #sqlstatement
Close mycur
deallocate mycur
select * from @All_Info
END
--sp_configure 'xp_cmdshell',1
--reconfigure