Click here to Skip to main content
15,914,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following problem. I am trying to build a query to show blocking and non-blocking queries. I got a query from the Internet which uses master.sys.sysprocesses. When googling it I saw that it was depreciated. The Microsoft website says to rather use the following 3 tables.
sys.dm_exec_connections
sys.dm_exec_sessions
sys.dm_exec_requests
I amended my query to join these three tables on session_id column. Two of the Tables namely (sys.dm_exec_sessions,sys.dm_exec_requests) have a column called database_id which is use in the function DB_NAME(database_id) which gives me a name of a database.

However that database is not the database against which the query is run. For example. I use Microsoft Sql Server Management Studio to run a query which I run while connected to the master database however the query is a select and looks something like this.
SELECT ColumnA, ColumnB, ColumnC
FROM MyDatabase.MySchema.MyTable


When I then run the following query with the SPID of the above query :
select DB_NAME(database_id) from sys.dm_exec_sessions where session_id = @varSPID
select DB_NAME(database_id) from sys.dm_exec_requests where session_id = @varSPI
D

Where @varSPID is an integer variable of the first query. However it always just says [master] database instead of saying [MyDatabase]. What table can I use to determine the true table against which the query has executed ?
Posted
Comments
TheSqlGuy 20-Jun-14 23:08pm    
I believe SSMS has a built in report that you can use to view blocking/blocked transactions. Dell software has some Toad products that could also assist you with this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900