.NET executes a SQL query and Active Monitor shows multiple rows blocking each otherSelf blocking sessionInsert randomly takes 10+ seconds to completeDTUTIL performance slower in SQL Server 2012?Sch-M WAIT blocks Sch-S in SQL Server 2014 but not SQL Server 2008 R2?SQL Server sometimes uses a lot more cpu for queryDatabase role to allow .NET program to retrieve MSDB table and view rowsSQL database performance optimizationHow to track SSIS memory and CPU performance?“Unrelated” INSERT and UPDATE blocking each otherSSIS execution timeout expired
Is it illegal to withhold someone's passport and green card in California?
Can White Castle?
Can humans ever directly see a few photons at a time? Can a human see a single photon?
Ndsolve problem with Sign (friction)
What happened to Steve's Shield in Iron Man 2?
Why do textbooks often include the solutions to odd or even numbered problems but not both?
Cut the gold chain
Does having had a visa for a country mean I used to be a citizen/national of that country?
Find the C-factor of a vote
Why tighten down in a criss-cross pattern?
Count All Possible Unique Combinations of Letters in a Word
Is it damaging to turn off a small fridge for two days every week?
When can you leave off “le/la” to say “it” in French?
Trainee keeps missing deadlines for independent learning
What is the origin of Scooby-Doo's name?
What size of powerbank will I need to power a phone and DSLR for 2 weeks?
How does DC work with natural 20?
What exactly is the 'online' in OLAP and OLTP?
Silly doubt about tidal effects and Einstein Field Equations
What could exist inside and between the walls of a Dyson Sphere?
What does "play with your toy’s toys" mean?
Why does the Saturn V have standalone inter-stage rings?
Can there be an UN resolution to remove a country from the UNSC?
Why does Linux list NVMe drives as /dev/nvme0 instead of /dev/sda?
.NET executes a SQL query and Active Monitor shows multiple rows blocking each other
Self blocking sessionInsert randomly takes 10+ seconds to completeDTUTIL performance slower in SQL Server 2012?Sch-M WAIT blocks Sch-S in SQL Server 2014 but not SQL Server 2008 R2?SQL Server sometimes uses a lot more cpu for queryDatabase role to allow .NET program to retrieve MSDB table and view rowsSQL database performance optimizationHow to track SSIS memory and CPU performance?“Unrelated” INSERT and UPDATE blocking each otherSSIS execution timeout expired
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I use .NET to execute SQL operations on SQL Server 2014, here's the code used:
using(SqlConnection conn = new SqlConnection(connectionString))
//https://stackoverflow.com/questions/1880471/capture-stored-procedure-print-output-in-net
conn.InfoMessage += new SqlInfoMessageEventHandler(logSqlMessages);
conn.Open();
using(SqlCommand stmt = new SqlCommand
Connection = conn,
CommandText = sql,
CommandTimeout = 30000 // The time in seconds to wait for the command to execute. The default is 30 seconds.
//,CommandType = CommandType.StoredProcedure
)
affectedRecords = stmt.ExecuteNonQuery();
// using stmt
// using conn
When I look at Active Monitor, there are tens of rows referencing the same operation. They all have the same session_id, some of them have Task State running and most of them are suspended. Some of them have LastWaitTime CXPACKET and most are PAGEIOLATCH_SH.
I also ran a query on SQL Server and same behavior happened on Active Monitor.
Maybe it's a normal behavior of it, but it's odd that a SELECT operation creates multiple rows and blocks itself like that. Any idea of what may be causing it?
sql-server sql-server-2014 optimization ado.net activity-monitor
add a comment |
I use .NET to execute SQL operations on SQL Server 2014, here's the code used:
using(SqlConnection conn = new SqlConnection(connectionString))
//https://stackoverflow.com/questions/1880471/capture-stored-procedure-print-output-in-net
conn.InfoMessage += new SqlInfoMessageEventHandler(logSqlMessages);
conn.Open();
using(SqlCommand stmt = new SqlCommand
Connection = conn,
CommandText = sql,
CommandTimeout = 30000 // The time in seconds to wait for the command to execute. The default is 30 seconds.
//,CommandType = CommandType.StoredProcedure
)
affectedRecords = stmt.ExecuteNonQuery();
// using stmt
// using conn
When I look at Active Monitor, there are tens of rows referencing the same operation. They all have the same session_id, some of them have Task State running and most of them are suspended. Some of them have LastWaitTime CXPACKET and most are PAGEIOLATCH_SH.
I also ran a query on SQL Server and same behavior happened on Active Monitor.
Maybe it's a normal behavior of it, but it's odd that a SELECT operation creates multiple rows and blocks itself like that. Any idea of what may be causing it?
sql-server sql-server-2014 optimization ado.net activity-monitor
add a comment |
I use .NET to execute SQL operations on SQL Server 2014, here's the code used:
using(SqlConnection conn = new SqlConnection(connectionString))
//https://stackoverflow.com/questions/1880471/capture-stored-procedure-print-output-in-net
conn.InfoMessage += new SqlInfoMessageEventHandler(logSqlMessages);
conn.Open();
using(SqlCommand stmt = new SqlCommand
Connection = conn,
CommandText = sql,
CommandTimeout = 30000 // The time in seconds to wait for the command to execute. The default is 30 seconds.
//,CommandType = CommandType.StoredProcedure
)
affectedRecords = stmt.ExecuteNonQuery();
// using stmt
// using conn
When I look at Active Monitor, there are tens of rows referencing the same operation. They all have the same session_id, some of them have Task State running and most of them are suspended. Some of them have LastWaitTime CXPACKET and most are PAGEIOLATCH_SH.
I also ran a query on SQL Server and same behavior happened on Active Monitor.
Maybe it's a normal behavior of it, but it's odd that a SELECT operation creates multiple rows and blocks itself like that. Any idea of what may be causing it?
sql-server sql-server-2014 optimization ado.net activity-monitor
I use .NET to execute SQL operations on SQL Server 2014, here's the code used:
using(SqlConnection conn = new SqlConnection(connectionString))
//https://stackoverflow.com/questions/1880471/capture-stored-procedure-print-output-in-net
conn.InfoMessage += new SqlInfoMessageEventHandler(logSqlMessages);
conn.Open();
using(SqlCommand stmt = new SqlCommand
Connection = conn,
CommandText = sql,
CommandTimeout = 30000 // The time in seconds to wait for the command to execute. The default is 30 seconds.
//,CommandType = CommandType.StoredProcedure
)
affectedRecords = stmt.ExecuteNonQuery();
// using stmt
// using conn
When I look at Active Monitor, there are tens of rows referencing the same operation. They all have the same session_id, some of them have Task State running and most of them are suspended. Some of them have LastWaitTime CXPACKET and most are PAGEIOLATCH_SH.
I also ran a query on SQL Server and same behavior happened on Active Monitor.
Maybe it's a normal behavior of it, but it's odd that a SELECT operation creates multiple rows and blocks itself like that. Any idea of what may be causing it?
sql-server sql-server-2014 optimization ado.net activity-monitor
sql-server sql-server-2014 optimization ado.net activity-monitor
edited 6 hours ago
MDCCL
7,06331847
7,06331847
asked 9 hours ago
HikariHikari
61251929
61251929
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Multiple rows in activity monitor for the same SPID means your query has been chosen to be executed in parallel across multiple threads.

Each row on Activity Monitor actually represents one ECID, not one SPID.
Activity monitor only exposes the SPID column (session_id), but there is an additional column exposed in sys.sysprocesses called ECID (Execution Context ID) - this is a unique identifier for each thread the query is utilising.
The sysprocesses system view is deprecated, but you can find ECID by another name (exec_context_id) in the sys.dm_os_tasks view (as well as other task-related views).
Here is a sample query that captures all of the execution context IDs associated with queries running in a particular session, and what, if anything, they are waiting on:
SELECT
dot.session_id,
dot.exec_context_id,
dot.task_state,
dowt.wait_type,
dowt.wait_duration_ms,
dowt.blocking_session_id,
dowt.resource_description
FROM sys.dm_os_tasks dot
LEFT JOIN sys.dm_os_waiting_tasks dowt
ON dowt.exec_context_id = dot.exec_context_id
AND dowt.session_id = dot.session_id
WHERE dot.session_id = 51
ORDER BY exec_context_id;
In SQL 2016 two new columns were added to sys.dm_exec_requests - DOP and parallel_worker_count - these can be used to check the whether the request is running in parallel or not.
Another key item to note is that the CXPACKET wait is inherently a parallelism wait - this by itself tells us the query is using more than one thread.
The PAGEIOLATCH_SH is a wait indicating those threads are reading data from disk into memory.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "182"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f240921%2fnet-executes-a-sql-query-and-active-monitor-shows-multiple-rows-blocking-each-o%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Multiple rows in activity monitor for the same SPID means your query has been chosen to be executed in parallel across multiple threads.

Each row on Activity Monitor actually represents one ECID, not one SPID.
Activity monitor only exposes the SPID column (session_id), but there is an additional column exposed in sys.sysprocesses called ECID (Execution Context ID) - this is a unique identifier for each thread the query is utilising.
The sysprocesses system view is deprecated, but you can find ECID by another name (exec_context_id) in the sys.dm_os_tasks view (as well as other task-related views).
Here is a sample query that captures all of the execution context IDs associated with queries running in a particular session, and what, if anything, they are waiting on:
SELECT
dot.session_id,
dot.exec_context_id,
dot.task_state,
dowt.wait_type,
dowt.wait_duration_ms,
dowt.blocking_session_id,
dowt.resource_description
FROM sys.dm_os_tasks dot
LEFT JOIN sys.dm_os_waiting_tasks dowt
ON dowt.exec_context_id = dot.exec_context_id
AND dowt.session_id = dot.session_id
WHERE dot.session_id = 51
ORDER BY exec_context_id;
In SQL 2016 two new columns were added to sys.dm_exec_requests - DOP and parallel_worker_count - these can be used to check the whether the request is running in parallel or not.
Another key item to note is that the CXPACKET wait is inherently a parallelism wait - this by itself tells us the query is using more than one thread.
The PAGEIOLATCH_SH is a wait indicating those threads are reading data from disk into memory.
add a comment |
Multiple rows in activity monitor for the same SPID means your query has been chosen to be executed in parallel across multiple threads.

Each row on Activity Monitor actually represents one ECID, not one SPID.
Activity monitor only exposes the SPID column (session_id), but there is an additional column exposed in sys.sysprocesses called ECID (Execution Context ID) - this is a unique identifier for each thread the query is utilising.
The sysprocesses system view is deprecated, but you can find ECID by another name (exec_context_id) in the sys.dm_os_tasks view (as well as other task-related views).
Here is a sample query that captures all of the execution context IDs associated with queries running in a particular session, and what, if anything, they are waiting on:
SELECT
dot.session_id,
dot.exec_context_id,
dot.task_state,
dowt.wait_type,
dowt.wait_duration_ms,
dowt.blocking_session_id,
dowt.resource_description
FROM sys.dm_os_tasks dot
LEFT JOIN sys.dm_os_waiting_tasks dowt
ON dowt.exec_context_id = dot.exec_context_id
AND dowt.session_id = dot.session_id
WHERE dot.session_id = 51
ORDER BY exec_context_id;
In SQL 2016 two new columns were added to sys.dm_exec_requests - DOP and parallel_worker_count - these can be used to check the whether the request is running in parallel or not.
Another key item to note is that the CXPACKET wait is inherently a parallelism wait - this by itself tells us the query is using more than one thread.
The PAGEIOLATCH_SH is a wait indicating those threads are reading data from disk into memory.
add a comment |
Multiple rows in activity monitor for the same SPID means your query has been chosen to be executed in parallel across multiple threads.

Each row on Activity Monitor actually represents one ECID, not one SPID.
Activity monitor only exposes the SPID column (session_id), but there is an additional column exposed in sys.sysprocesses called ECID (Execution Context ID) - this is a unique identifier for each thread the query is utilising.
The sysprocesses system view is deprecated, but you can find ECID by another name (exec_context_id) in the sys.dm_os_tasks view (as well as other task-related views).
Here is a sample query that captures all of the execution context IDs associated with queries running in a particular session, and what, if anything, they are waiting on:
SELECT
dot.session_id,
dot.exec_context_id,
dot.task_state,
dowt.wait_type,
dowt.wait_duration_ms,
dowt.blocking_session_id,
dowt.resource_description
FROM sys.dm_os_tasks dot
LEFT JOIN sys.dm_os_waiting_tasks dowt
ON dowt.exec_context_id = dot.exec_context_id
AND dowt.session_id = dot.session_id
WHERE dot.session_id = 51
ORDER BY exec_context_id;
In SQL 2016 two new columns were added to sys.dm_exec_requests - DOP and parallel_worker_count - these can be used to check the whether the request is running in parallel or not.
Another key item to note is that the CXPACKET wait is inherently a parallelism wait - this by itself tells us the query is using more than one thread.
The PAGEIOLATCH_SH is a wait indicating those threads are reading data from disk into memory.
Multiple rows in activity monitor for the same SPID means your query has been chosen to be executed in parallel across multiple threads.

Each row on Activity Monitor actually represents one ECID, not one SPID.
Activity monitor only exposes the SPID column (session_id), but there is an additional column exposed in sys.sysprocesses called ECID (Execution Context ID) - this is a unique identifier for each thread the query is utilising.
The sysprocesses system view is deprecated, but you can find ECID by another name (exec_context_id) in the sys.dm_os_tasks view (as well as other task-related views).
Here is a sample query that captures all of the execution context IDs associated with queries running in a particular session, and what, if anything, they are waiting on:
SELECT
dot.session_id,
dot.exec_context_id,
dot.task_state,
dowt.wait_type,
dowt.wait_duration_ms,
dowt.blocking_session_id,
dowt.resource_description
FROM sys.dm_os_tasks dot
LEFT JOIN sys.dm_os_waiting_tasks dowt
ON dowt.exec_context_id = dot.exec_context_id
AND dowt.session_id = dot.session_id
WHERE dot.session_id = 51
ORDER BY exec_context_id;
In SQL 2016 two new columns were added to sys.dm_exec_requests - DOP and parallel_worker_count - these can be used to check the whether the request is running in parallel or not.
Another key item to note is that the CXPACKET wait is inherently a parallelism wait - this by itself tells us the query is using more than one thread.
The PAGEIOLATCH_SH is a wait indicating those threads are reading data from disk into memory.
edited 7 hours ago
Josh Darnell
9,54732347
9,54732347
answered 8 hours ago
George.PalaciosGeorge.Palacios
3,479928
3,479928
add a comment |
add a comment |
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f240921%2fnet-executes-a-sql-query-and-active-monitor-shows-multiple-rows-blocking-each-o%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown