request_id in sys.dm_os_tasks wrong when using MARS - by Adam Machanic

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


5
0
Sign in
to vote
ID 490178 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 9/16/2009 8:44:10 AM
Access Restriction Public

Description

When a session is using MARS, the request_id column in sys.dm_os_tasks can have the wrong values, reflecting a request that is not really associated with the task.

I tested this in both SQL Server 2005 and 2008.
Sign in to post a comment.
Posted by Microsoft on 4/21/2010 at 7:58 PM
Adam,

Thanks for reporting it. Yes, it's a real bug. The DMV sys.dm_os_tasks is reporting the active MARS request for the corresponding session and not the one associated with the task. The fix was made to SQL Server 2008 SP2 and Denali (next SQL version).

Thanks,
Fabricio Voznika
Posted by Umachandar [MSFT] on 9/22/2009 at 6:46 PM
Hi Adam,
Thanks for reporting the issue. We will investigate the discrepancy between the two DMVs and correct dm_os_tasks DMV.

--
Umachandar, SQL Programmability Team
Posted by Adam Machanic on 9/16/2009 at 8:44 AM
Here is the C# program:

--------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace mars
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder();

            //Replace DataSource with your database
            sb.DataSource = @".\ss2008";
            sb.InitialCatalog = "master";
            sb.IntegratedSecurity = true;
            sb.MultipleActiveResultSets = true;
            sb.ApplicationName = "MARS TEST";

            using (SqlConnection conn = new SqlConnection(sb.ConnectionString))
            {
                conn.Open();

                SqlTransaction t = conn.BeginTransaction();

                SqlCommand comm1 = new SqlCommand();
                comm1.Connection = conn;
                comm1.CommandText = "select * from sys.all_objects o join sys.all_columns c on o.object_id = c.object_id";
                comm1.Transaction = t;
                var r1 = comm1.ExecuteReader();

                SqlCommand comm2 = new SqlCommand();
                comm2.Connection = conn;
                comm2.CommandText = "select * from sys.all_objects o join sys.all_views v on o.object_id = v.object_id";
                comm2.Transaction = t;
                var r2 = comm2.ExecuteReader();

                while (r1.Read())
                {
                    while (r2.Read())
                    {
                        System.Threading.Thread.Sleep(300000);
                    }
                }
            }
        }
    }
}
--------