Home > php教程 > php手册 > body text

MSSQL 查看一个数据库的连接用户数

WBOY
Release: 2016-06-06 20:01:16
Original
1240 people have browsed it

1.通过系统的性能来查看: 开始-管理工具-性能(或者是运行里面输入 mmc)然后通过 添加计数器添加 SQL 的常用统计 然后在下面列出的项目里面选择用户连接就可以时时查询到数据库的连接数了。 不过此方法的话需要有访问那台计算机的权限,就是要通过windows

1.通过系统的“性能”来查看:
开始->管理工具->性能(或者是运行里面输入 mmc)然后通过
添加计数器添加 SQL 的常用统计 然后在下面列出的项目里面选择用户连接就可以时时查询到数据库的连接数了。
不过此方法的话需要有访问那台计算机的权限,就是要通过windows账户登陆进去才可以添加此计数器。


2.通过系统表来查询:
SELECT * FROM
[Master].[dbo].[SYSPROCESSES] WHERE [DBID]
IN
(
  SELECT
   [DBID]
  FROM
   [Master].[dbo].[SYSDATABASES]
  WHERE
   NAME='databaseName'
)
databaseName 是需要查看的数据库,然后查询出来的行数,就是当前的连接数。不过里面还有一些别的状态可以做参考用。


3.通过系统过程来查询:
SP_WHO 'loginName'
loginName 是当然登陆Sql的用户名,一般程序里面都会使用一个username来登陆SQL这样通过这个用户名就能查看到此用户名登陆之后占用的连接了。
如果不写loginName,那么返回的就是所有的连接。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!