.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;








5















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?










share|improve this question






























    5















    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?










    share|improve this question


























      5












      5








      5








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 6 hours ago









      MDCCL

      7,06331847




      7,06331847










      asked 9 hours ago









      HikariHikari

      61251929




      61251929




















          1 Answer
          1






          active

          oldest

          votes


















          11














          Multiple rows in activity monitor for the same SPID means your query has been chosen to be executed in parallel across multiple threads.



          NUTS



          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.






          share|improve this answer



























            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
            );



            );













            draft saved

            draft discarded


















            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









            11














            Multiple rows in activity monitor for the same SPID means your query has been chosen to be executed in parallel across multiple threads.



            NUTS



            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.






            share|improve this answer





























              11














              Multiple rows in activity monitor for the same SPID means your query has been chosen to be executed in parallel across multiple threads.



              NUTS



              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.






              share|improve this answer



























                11












                11








                11







                Multiple rows in activity monitor for the same SPID means your query has been chosen to be executed in parallel across multiple threads.



                NUTS



                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.






                share|improve this answer















                Multiple rows in activity monitor for the same SPID means your query has been chosen to be executed in parallel across multiple threads.



                NUTS



                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.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 7 hours ago









                Josh Darnell

                9,54732347




                9,54732347










                answered 8 hours ago









                George.PalaciosGeorge.Palacios

                3,479928




                3,479928



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                    Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                    François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480