日期:2014-05-18  浏览次数:20560 次

获取当前SQLServer连接数
网上找了很久,没有答案,大家有什么解决办法吗?

------解决方案--------------------
SQL code

2000:
select * from sysprocesses
2005或者2008:
Fanr  12:17:32
2005 以上 非2012 
select * from sys.sysprocesses

------解决方案--------------------
select count(distinct hostname) from master..sysprocesses
------解决方案--------------------
SQL code
select count(distinct hostname) from master..sysprocesses  --此句获取本服务器上的连接人数

select count(distinct hostname) from master..sysprocesses
where  hostname <> '服务器名\实例名' --- 此句获取本服务器上该实例下的连接人数

select count(distinct hostname) from master..sysprocesses
where  hostname <> 'SVR005DE610\SQL2008' and  dbid=db_id('数据库名')  ---此句获取本服务器上该实例下该数据库的连接人数

------解决方案--------------------
SQL code

select count(distinct hostname) from master..sysprocesses 
--获取主机数
居然让小F姐姐抢了风头

------解决方案--------------------
用户进程的spid都是大于50的,
SQL code

 select count(*) '连接数'
 from master.dbo.sysprocesses 
 where spid>50

------解决方案--------------------
应该是这个吧,
sys.dm_exec_session
楼上的都是2000的,2005及2008只是保留,但是不推荐。
------解决方案--------------------
有很多重复的空的。
应该如
select count(distinct hostname) from master..sysprocesses

探讨
用户进程的spid都是大于50的,

SQL code

select count(*) '连接数'
from master.dbo.sysprocesses
where spid>50