sys.dm_exec_connections (Transact-SQL)

返回有关与此 SQL Server 实例建立的连接的信息以及每个连接的详细信息。

适用范围:SQL Server(SQL Server 2008 至当前版本),Windows Azure SQL Database(初始版本至当前版本)。

列名

数据类型

说明

session_id

int

标识与此连接关联的会话。 可以为 Null。

most_recent_session_id

int

表示与此连接关联的最近请求的会话 ID。 (另一个会话可以重用 SOAP 连接。)可以为 Null。

connect_time

datetime

连接建立时的时间戳。 不可为 Null。

net_transport

nvarchar(40)

说明该连接使用的物理传输协议。 不可为 Null。

备注

如果连接启用了多个活动结果集 (MARS),则将始终返回 Session

protocol_type

nvarchar(40)

指定负载的协议类型。 此参数当前可区分 TDS (TSQL) 和 SOAP。 可以为 Null。

protocol_version

int

与此连接关联的数据访问协议的版本。 可以为 Null。

endpoint_id

int

说明其连接类型的标识符。 此 endpoint_id 可用于查询 sys.endpoints 视图。 可以为 Null。

encrypt_option

nvarchar(40)

说明是否为此连接启用了加密的布尔值。 不可为 Null。

auth_scheme

nvarchar(40)

指定此连接使用的 SQL Server/Windows 身份验证方案。 不可为 Null。

node_affinity

smallint

标识与此连接关联的内存节点。 不可为 Null。

num_reads

int

此连接中已发生的读包次数。 可以为 Null。

num_writes

int

此连接中已发生的写数据包次数。 可以为 Null。

last_read

datetime

此连接中上一次发生读操作的时间戳。 可以为 Null。

last_write

datetime

此连接中上一次发生写操作的时间戳。 不可为 Null。

net_packet_size

int

用于信息和数据传输的网络包的大小。 可以为 Null。

client_net_address

varchar(48)

与此服务器连接的客户端的主机地址。 可以为 Null。

在 Windows Azure SQL Database 中,此列始终返回 NULL。

client_tcp_port

int

与此连接关联的客户端计算机上的端口号。 可以为 Null。

在 Windows Azure SQL Database 中,此列始终返回 NULL。

local_net_address

varchar(48)

表示此连接的目标服务器的 IP 地址。 只对使用 TCP 传输提供程序的连接可用。 可以为 Null。

在 Windows Azure SQL Database 中,此列始终返回 NULL。

local_tcp_port

int

如果此连接使用 TCP 传输,则表示此连接的目标服务器的 TCP 端口。 可以为 Null。

在 Windows Azure SQL Database 中,此列始终返回 NULL。

connection_id

uniqueidentifier

对每个连接进行唯一标识。 不可为 Null。

parent_connection_id

uniqueidentifier

标识 MARS 会话正在使用的主要连接。 可以为 Null。

most_recent_sql_handle

varbinary(64)

此连接上执行的上一个请求的 SQL 句柄。 most_recent_sql_handle 列始终与 most_recent_session_id 列同步。 可以为 Null。

权限

要求对服务器拥有 VIEW SERVER STATE 权限。

物理联接

sys.dm_exec_connections 的联接

关系基数

dm_exec_sessions.session_id

dm_exec_connections.session_id

一对一

dm_exec_requests.connection_id

dm_exec_connections.connection_id

多对一

dm_broker_connections.connection_id

dm_exec_connections.connection_id

一对一

示例

收集查询自有连接有关信息的典型查询。

SELECT 
    c.session_id, c.net_transport, c.encrypt_option, 
    c.auth_scheme, s.host_name, s.program_name, 
    s.client_interface_name, s.login_name, s.nt_domain, 
    s.nt_user_name, s.original_login_name, c.connect_time, 
    s.login_time 
FROM sys.dm_exec_connections AS c
JOIN sys.dm_exec_sessions AS s
    ON c.session_id = s.session_id
WHERE c.session_id = @@SPID;

请参阅

参考

动态管理视图和函数 (Transact-SQL)

与执行有关的动态管理视图和函数 (Transact-SQL)