石家庄网站制作联系电话:13292823610 郭先生 QQ咨询:您当前的位置:首页 > 网站制作

查看SQL数据库当前活动连接数

    来源:石家庄网站建设  发表时间: 2010年11月16日    作者:石家庄轻程网络  浏览次数:
使用MSSQL数据库,如果没有及时关闭连接则程序会把CPU占100%,所以在测试时一定要查看当前数据库的活动连接。
查看当前SQL数据库连接的基本语句为 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中

网站制作,重点是细节,所以,一定要记得关闭打开的数据库连接。

相关内容