如何实时查看数据库当前活动连接

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 shmily0929 的 blog

原来一直被这个问题所困扰,前些天在网上偶然发现解决的办法。现分享如下:
基本语句为 sp_who
我们可以把查询结果插入到我们自己定义的表(monitoruser)中
基本语句为
create table monitoruser
(                  spid int, 
                   ecid int,
                   status varchar(200),
                   loginame varchar(200),
                   hostname varchar(200),         \\根据sp_who的结果新建表结构          
                   blk varchar(200),
                   dbname varchar(200),
                   cmd varchar(200),
                   [datetime] [datetime] not null
 )
alter table [dbo].[monitoruser] with nocheck add
constraint [datetime] default (getdate()) for[datetime]  \\自动获取时间插到datetime列中
go
insert into monitoruser(spid,ecid,status,loginame,hostname,blk,dbname,cmd)
exec ('sp_who')    \\执行sp_who,将结果插入到monitoruser中

本文关键:如何实时查看数据库当前活动连接
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top