如何获取数据库服务器的连接数? 10zjh222]

发布时间:2016-12-8 6:14:46 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"如何获取数据库服务器的连接数? 10zjh222]",主要涉及到如何获取数据库服务器的连接数? 10zjh222]方面的内容,对于如何获取数据库服务器的连接数? 10zjh222]感兴趣的同学可以参考一下。

我想通过获取数据库的连接数来控制软件的使用,如果软件检测到当前数据库有3个连接了,如果再连接就报错. 注意不是@@connections之类的总连接数...... 如何获取数据库服务器的当前连接数呢?

select  db_name(dbid),* from  master..sysprocesses where spid>50      and db_name(dbid)='dbname'

如何查看SQL SERVER数据库当前连接数  1.通过管理工具 开始->管理工具->性能(或者是运行里面输入 mmc)然后通过添加计数器添加 SQL 的常用统计 然后在下面列出的项目里面选择用户连接就可以时时查询到数据库的连接数了。不过此方法的话需要有访问那台计算机的权限,就是要通过Windows账户登陆进去才可以添加此计数器。 2.通过系统表查询 SELECT * FROM [Master].[dbo].[SYSPROCESSES] WHERE [DBID] IN ( SELECT     [DBID] FROM     [Master].[dbo].[SYSDATABASES] WHERE     NAME='DBName' ) DBName 是需要查看的数据库,然后查询出来的行数,就是当前的连接数。不过里面还有一些别的状态可以做参考用。 例如:连到master这个数据库写如下语句 select * from sysprocesses where dbid in (select dbid from sysdatabases where name='MyDatabase') 将所有连接MyDatabase这个数据库的连接记录都求出来。 sysprocesses这个表记录所以连接到SQL SERVER数据库的连接。 3.通过系统的存储过程来查找 SP_WHO 'UserName' UserName 是当然登陆Sql的用户名,一般程序里面都会使用一个UserName来登陆SQL这样通过这个用户名就能查看到此用户名登陆之后占用的连接了。 如果不写UserName,那么返回的就是所有的连接。 SP_WHO 'sa' spid   ecid   status                         loginame                                                                                                                         hostname                                                                                                                         blk   dbname                                                                                                                           cmd               ------ ------ ------------------------------ -------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- ----- -------------------------------------------------------------------------------------------------------------------------------- ----------------  1      0      background                     sa                                                                                                                                                                                                                                                                0     NULL                                                                                                                             LAZY WRITER      2      0      background                     sa                                                                                                                                                                                                                                                                0     master                                                                                                                           SIGNAL HANDLER   3      0      sleeping                       sa                                                                                                                                                                                                                                                                0     NULL                                                                                                                             LOG WRITER       4      0      background                     sa                                                                                                                                                                                                                                                                0     NULL                                                                                                                             LOCK MONITOR     5      0      background                     sa                                                                                                                                                                                                                                                                0     master                                                                                                                           TASK MANAGER     6      0      background                     sa                                                                                                                                                                                                                                                                0     master                                                                                                                           TASK MANAGER     7      0      sleeping                       sa                                                                                                                                                                                                                                                                0     NULL                                                                                                                             CHECKPOINT SLEEP 8      0      background                     sa                                                                                                                                                                                                                                                                0     master                                                                                                                           TASK MANAGER     9      0      background                     sa                                                                                                                                                                                                                                                                0     master                                                                                                                           TASK MANAGER     10     0      background                     sa                                                                                                                                                                                                                                                                0     master                                                                                                                           TASK MANAGER     11     0      background                     sa                                                                                                                                                                                                                                                                0     master                                                                                                                           TASK MANAGER     12     0      background                     sa                                                                                                                                                                                                                                                                0     master                                                                                                                           TASK MANAGER     13     0      background                     sa                                                                                                                                                                                                                                                                0     master                                                                                                                           TASK MANAGER     51     0      runnable                       sa                                                                                                                               CHINA-668C6A66D                                                                                                                  0     master                                                                                                                           SELECT           52     0      sleeping                       sa                                                                                                                               CHINA-668C6A66D                                                                                                                  0     master                                                                                                                           AWAITING COMMAND (所影响的行数为 15 行)

学习

上一篇:(求助)vista sql server 2005 安装后无本地服务器 怎么解决? 20fredrickhu]
下一篇:我要存大文件到Varbinary(max)中,定义这个存储过程不行呢? 20zjh222]

相关文章

相关评论