如何查找并发 SQL Server 连接数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13941036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:41:41  来源:igfitidea点击:

How to find the number of concurrent SQL Server connections

sqlsql-serverconnection

提问by user1158745

I have a SQL Server that is reaching the max limit of concurrent connections. I have many different servers & services connecting to one SQL Server at the same time.

我有一个达到最大并发连接限制的 SQL Server。我有许多不同的服务器和服务同时连接到一个 SQL Server。

I did find another query that seems to work:

我确实找到了另一个似乎有效的查询:

SELECT DB_NAME(dbid) AS DBName,
       COUNT(dbid)   AS NumberOfConnections,
       loginame      AS LoginName,
       nt_domain     AS NT_Domain,
       nt_username   AS NT_UserName,
       hostname      AS HostName
FROM   sys.sysprocesses
WHERE  dbid > 0
GROUP  BY dbid,
          hostname,
          loginame,
          nt_domain,
          nt_username
ORDER  BY NumberOfConnections DESC;

However, this gives me the number of connections which is good. How do i further dig down this to find to see the each connection and what action they are doing?

但是,这给了我很好的连接数。我如何进一步深入挖掘以查看每个连接以及它们正在执行的操作?

回答by Xabur

the sql command "sp_who" which provides information about current users, sessions, and processes in an instance of the Microsoft SQL Server Database Engine (MSDN) From here, you should be able to send the results into a temp table and group them by servername.

sql 命令“sp_who”在 Microsoft SQL Server 数据库引擎 ( MSDN)实例中提供有关当前用户、会话和进程的信息,从这里,您应该能够将结果发送到临时表中并按服务器名对它们进行分组.

such as the following...

例如以下...

CREATE TABLE #tbl (
      spid      int
    , ecid      int
    , status    varchar(50)
    , loginame  varchar(255)
    , hostname  varchar(255)
    , blk       varchar(50)
    , dbname    varchar(255)
    , cmd       varchar(255)
    , request_id varchar(255)
    )
GO

INSERT INTO #tbl EXEC sp_who

SELECT COUNT(0), hostname FROM #tbl group by hostname

DROP TABLE #tbl
GO

回答by the_marcelo_r

Are you talking about how to check the connections that are reaching your SQL Server instance? How about some DOS commands? try to search for the port 1433 or for the PID of your SQL Server process.

您是在谈论如何检查到达您的 SQL Server 实例的连接吗?一些DOS命令怎么样?尝试搜索端口 1433 或 SQL Server 进程的 PID。

netstat -nao | find "1433"

netstat -nao | 找到“1433”

To find the PID (process identifier) that you are looking for, just go to your task manager and customize the processes view, mode details here: http://www.mydigitallife.info/how-to-get-and-view-process-identifier-process-id-or-pid-on-windows/

要查找您要查找的 PID(进程标识符),只需转到您的任务管理器并自定义进程视图,此处的模式详细信息:http: //www.mydigitallife.info/how-to-get-and-view-进程标识符进程 ID 或 pid-on-windows/