欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

如何获取SQLServer数据库的连接数

程序员文章站 2022-04-21 13:20:27
...

欢迎进入Windows社区论坛,与300万技术人员互动交流 >>进入 1: V_SYS_CONTRACTIONS (获取系统连接数) SELECT COUNT(*) AS CONNECTIONS FROM master.sys.sysprocesses 2: V_SYS_DB_CONTRACTIONS(获取某数据的连接数) SELECT hostname, program_name, ho

欢迎进入Windows社区论坛,与300万技术人员互动交流 >>进入

  1: V_SYS_CONTRACTIONS (获取系统连接数)

  SELECT COUNT(*) AS CONNECTIONS FROM master.sys.sysprocesses

  2: V_SYS_DB_CONTRACTIONS(获取某数据的连接数)

  SELECT hostname, program_name, hostprocess, cmd, spid, kpid, blocked, waittype,waittime, lastwaittype, waitresource, dbid, uid, cpu, physical_io, memusage,login_time,

  last_batch, ecid,open_tran, status, sid, nt_domain, nt_username, net_address, net_library,loginame, context_info, sql_handle, stmt_start, stmt_end, request_id

  FROM master.sys.sysprocesses

  WHERE (dbid =

  (SELECT dbid

  FROM master.sys.sysdatabases

  WHERE (name = 'XXDBName')))

  3:V_SYS_NET_CONRACTIONS(获取网路地址连接数)

  SELECT COUNT(DISTINCT net_address) - 1 AS connectnum FROM master.sys.sysprocesses

  4: V_SYS_USER_CONTRACTIONS(获取用户连接数)

  SELECT cntr_value AS User_Connections

  FROM master.sys.sysperfinfo AS p

  WHERE (object_name = 'SQLServer:General Statistics')

  AND (counter_name = 'User Connections')

如何获取SQLServer数据库的连接数