Skip to content

Commit 8232ee4

Browse files
authored
Merge pull request #22277 from dimitri-furman/dfurman1
Clarified DMV behavior with MARS
2 parents 741f7f5 + c83b4bf commit 8232ee4

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

docs/relational-databases/system-dynamic-management-views/sys-dm-exec-connections-transact-sql.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
description: "sys.dm_exec_connections (Transact-SQL)"
3-
title: "sys.dm_exec_connections (Transact-SQL) | Microsoft Docs"
2+
description: "sys.dm_exec_connections (Transact-SQL) returns information about the connections established to this instance of the database engine and the details of each connection."
3+
title: "sys.dm_exec_connections (Transact-SQL)"
44
ms.custom: ""
5-
ms.date: "4/18/2022"
5+
ms.date: "5/31/2022"
66
ms.prod: sql
77
ms.prod_service: "database-engine, sql-database"
88
ms.reviewer: ""
@@ -17,14 +17,13 @@ dev_langs:
1717
- "TSQL"
1818
helpviewer_keywords:
1919
- "sys.dm_exec_connections dynamic management view"
20-
ms.assetid: 6bd46fe1-417d-452d-a9e6-5375ee8690d8
2120
author: rwestMSFT
2221
ms.author: randolphwest
2322
monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current|| = azure-sqldw-latest"
2423
---
2524
# sys.dm_exec_connections (Transact-SQL)
2625

27-
[!INCLUDE [sql-asdb-asa](../../includes/applies-to-version/sql-asdb-asa.md)]
26+
[!INCLUDE [sql-asdb-asdbmi-asa](../../includes/applies-to-version/sql-asdb-asdbmi-asa.md)]
2827

2928
Returns information about the connections established to this instance of the database engine and the details of each connection. Returns server wide connection information for SQL Server and Azure SQL Managed Instance. Returns connection information for the current database in Azure SQL Database. Returns connection information for all databases in the same elastic pool for databases in [elastic pools](/azure/azure-sql/database/elastic-pool-overview) in Azure SQL Database.
3029

@@ -36,10 +35,10 @@ Returns information about the connections established to this instance of the da
3635
|session_id|**int**|Identifies the session associated with this connection. Is nullable.|
3736
|most_recent_session_id|**int**|Represents the session ID for the most recent request associated with this connection. (SOAP connections can be reused by another session.) Is nullable.|
3837
|connect_time|**datetime**|Timestamp when connection was established. Is not nullable.|
39-
|net_transport|**nvarchar(40)**|Always returns **Session** when a connection has multiple active result sets (MARS) enabled.<br /><br /> **Note:** Describes the physical transport protocol that is used by this connection. Is not nullable.|
38+
|net_transport|**nvarchar(40)**|When MARS is used, returns **Session** for each additional connection associated with a MARS logical session.<br /><br /> **Note:** Describes the physical transport protocol that is used by this connection. Is not nullable.|
4039
|protocol_type|**nvarchar(40)**|Specifies the protocol type of the payload. It currently distinguishes between TDS ("TSQL"), "SOAP", and "Database Mirroring". Is nullable.|
4140
|protocol_version|**int**|Version of the data access protocol associated with this connection. Is nullable.|
42-
|endpoint_id|**int**|An identifier that describes what type of connection it is. This endpoint_id can be used to query the sys.endpoints view. Is nullable.|
41+
|endpoint_id|**int**|An identifier that describes what type of connection it is. This `endpoint_id` can be used to query the `sys.endpoints` view. Is nullable.|
4342
|encrypt_option|**nvarchar(40)**|Boolean value to describe whether encryption is enabled for this connection. Is not nullable.|
4443
|auth_scheme|**nvarchar(40)**|Specifies [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]/Windows Authentication scheme used with this connection. Is not nullable.|
4544
|node_affinity|**smallint**|Identifies the memory node to which this connection has affinity. Is not nullable.|
@@ -54,26 +53,30 @@ Returns information about the connections established to this instance of the da
5453
|local_tcp_port|**int**|Represents the server TCP port that this connection targeted if it were a connection using the TCP transport. Is nullable.<br /><br /> In [!INCLUDE[ssSDSfull](../../includes/sssdsfull-md.md)], this column always returns NULL.|
5554
|connection_id|**uniqueidentifier**|Identifies each connection uniquely. Is not nullable.|
5655
|parent_connection_id|**uniqueidentifier**|Identifies the primary connection that the MARS session is using. Is nullable.|
57-
|most_recent_sql_handle|**varbinary(64)**|The SQL handle of the last request executed on this connection. The most_recent_sql_handle column is always in sync with the most_recent_session_id column. Is nullable.|
56+
|most_recent_sql_handle|**varbinary(64)**|The SQL handle of the last request executed on this connection. The `most_recent_sql_handle` column is always in sync with the `most_recent_session_id` column. Is nullable.|
5857
|pdw_node_id|**int**|**Applies to**: [!INCLUDE[ssSDWfull](../../includes/sssdwfull-md.md)], [!INCLUDE[ssPDW](../../includes/sspdw-md.md)]<br /><br /> The identifier for the node that this distribution is on.|
5958

6059
## Permissions
6160

6261
On [!INCLUDE[ssNoVersion_md](../../includes/ssnoversion-md.md)] and SQL Managed Instance, requires `VIEW SERVER STATE` permission.
6362

6463
On Azure SQL Database **Basic**, **S0**, and **S1** service objectives, and for databases in **elastic pools**, the [server admin](/azure/azure-sql/database/logins-create-manage#existing-logins-and-user-accounts-after-creating-a-new-database) account, the [Azure Active Directory admin](/azure/azure-sql/database/authentication-aad-overview#administrator-structure) account, or membership in the `##MS_ServerStateReader##` [server role](/azure/azure-sql/database/security-server-roles) is required. On all other SQL Database service objectives, either the `VIEW DATABASE STATE` permission on the database, or membership in the `##MS_ServerStateReader##` server role is required.
65-
64+
6665
## Physical joins
67-
![Joins for sys.dm_exec_connections](../../relational-databases/system-dynamic-management-views/media/join-dm-exec-connections-1.gif "Joins for sys.dm_exec_connections")
66+
![Joins for sys.dm_exec_connections](../../relational-databases/system-dynamic-management-views/media/join-dm-exec-connections-1.gif "Joins for sys.dm_exec_connections")
6867

6968
## Relationship cardinalities
7069

7170
| First element | Second element | Relationship |
7271
| --------------| -------------- | ------------ |
73-
|dm_exec_sessions.session_id|dm_exec_connections.session_id|One-to-one|
74-
|dm_exec_requests.connection_id|dm_exec_connections.connection_id|Many to one|
75-
|dm_broker_connections.connection_id|dm_exec_connections.connection_id|One to one|
76-
72+
|[sys.dm_exec_sessions](sys-dm-exec-sessions-transact-sql.md).session_id|sys.dm_exec_connections.session_id|One-to-zero or one-to-many|
73+
|[sys.dm_exec_requests](sys-dm-exec-requests-transact-sql.md).connection_id|sys.dm_exec_connections.connection_id|Many-to-one|
74+
|[sys.dm_broker_connections](sys-dm-broker-connections-transact-sql.md).connection_id|sys.dm_exec_connections.connection_id|One-to-one|
75+
76+
Most commonly, for each row in `sys.dm_exec_connections` there is a single matching row in `sys.dm_exec_sessions`. However, in some cases such as system internal sessions or [Service Broker](../../database-engine/configure-windows/sql-server-service-broker.md) activation procedures, there may be a row in `sys.dm_exec_sessions` without a matching row in `sys.dm_exec_connections`.
77+
78+
When MARS is used, there may be multiple rows in `sys.dm_exec_connections` for a row in `sys.dm_exec_sessions`, one row for the parent connection, and one row for each MARS logical session. The latter rows can be identified by the value in the `net_transport` column being set to **Session**. For these connections, the value in the `connection_id` column of `sys.dm_exec_connections` matches the value in the `connection_id` column of `sys.dm_exec_requests` for MARS requests in progress.
79+
7780
## Examples
7881

7982
The following Transact-SQL query gathers information about a query's own connection.
@@ -98,4 +101,4 @@ Learn more about related concepts in the following articles:
98101
- [Execution Related Dynamic Management Views and Functions &#40;Transact-SQL&#41;](../../relational-databases/system-dynamic-management-views/execution-related-dynamic-management-views-and-functions-transact-sql.md)
99102
- [sys.dm_exec_sessions (Transact-SQL)](sys-dm-exec-sessions-transact-sql.md)
100103
- [sys.dm_exec_sql_text (Transact-SQL)](sys-dm-exec-sql-text-transact-sql.md)
101-
- [sys.dm_pdw_exec_connections (Transact-SQL)](sys-dm-pdw-exec-connections-transact-sql.md)
104+
- [sys.dm_pdw_exec_connections (Transact-SQL)](sys-dm-pdw-exec-connections-transact-sql.md)

0 commit comments

Comments
 (0)