我發現這個查詢,其中RESOURCE_ASSOCIATED_ENTITY_ID被解碼,並且基於resource_type使用 ,並且在某些情況下我發現它不能被解碼。
/* LOCK MONITOR ON CURRENT schema connections */
Select
GETDATE() as Current_Time1,
es.session_id,
db_name(sp.dbid) As DatabaseName,
es.status,
substring((Select text
From sys.dm_exec_sql_text(sp.sql_handle)),1,128) As LastSQLText,
es.host_name,
es.login_time,
es.login_name,
es.program_name,
Convert(float, Round((IsNull(es.cpu_time, 0.0)/1000.00),0)) As CPU_Time_in_seconds,
Convert(float, Round((IsNull(es.lock_timeout, 0.0)/1000.00),0)) as lock_timeout_in_seconds,
tl.resource_type As LockType,
tl.request_mode,
tl.resource_associated_entity_id,
CASE
WHEN tl.resource_type = 'OBJECT'
THEN OBJECT_NAME(tl.resource_associated_entity_id)
WHEN tl.resource_type IN ('KEY', 'PAGE', 'RID')
THEN ( SELECT object_name(object_id)
FROM sys.partitions ps1
WHERE ps1.hobt_id=tl.resource_associated_entity_id
)
ELSE 'n.a.'
END AS ObjectName,
tl.request_status As LockStatus,
ec.connect_time,
ec.net_transport,
ec.client_net_address,
er.connection_id,
Case er.blocking_session_id
When 0 Then 'Not Blocked'
When -2 Then 'Orphaned Distributed Transaction'
When -3 Then 'Deferred Recovery Transaction'
When -4 Then 'Latch owner not determined'
Else ''
End As Blocking_Type,
er.wait_type,
Convert(float, Round((IsNull(er.wait_time, 0.0)/
1000.00),0)) As Wait_Time_in_seconds,
er.percent_complete,
er.estimated_completion_time,
Convert(float, Round((IsNull(er.total_elapsed_time, 0.0)
/1000.00),0)) As Total_Elapsed_Time_in_seconds,
Case er.transaction_isolation_level
When 0 Then 'Unspecified'
When 1 Then 'ReadUncomitted'
When 2 Then 'ReadCommitted'
When 3 Then 'Repeatable'
When 4 Then 'Serializable'
When 5 Then 'Snapshot'
Else ''
End transaction_isolation_level
From master.sys.dm_exec_sessions es
Inner Join master.sys.sysprocesses sp
On sp.spid = es.session_id
Left Join master.sys.dm_exec_connections ec
On ec.session_id = es.session_id
Left Join master.sys.dm_exec_requests er
On er.session_id = es.session_id
Left Join master.sys.dm_tran_locks tl
On tl.request_session_id = es.session_id
Where es.session_id <> @@spid
And es.session_id = es.session_id
And sp.dbid = DB_ID() /* CURRENT DB TO MONITOR */
And tl.resource_type <> 'DATABASE';
raiserror('- ', 10, 3) with nowait;
WAITFOR DELAY '00:00:30';
GO 30
是什麼(選擇)OBJECT_NAME(RESOURCE_ASSOCIATED_ENTITY_ID)返回? – edosoft 2010-06-02 14:02:27
它返回NULL。我嘗試將RESOURCE_DATABASE_ID列的內容作爲第二個參數傳遞給OBJECT_NAME,但它沒有區別。 以下查詢返回OBJECT_NAME的一些值,但不是其他值,因爲ID似乎並不涉及模式範圍的對象,所以它們不存在於sys.all_objects中。他們可能會引用非模式範圍的對象,但關於如何查找所有非模式範圍的對象的信息非常少。 SELECT OBJECT_NAME(resource_associated_entity_id,resource_database_id)AS object_name,* FROM sys.dm_tran_locks WHERE resource_type ='OBJECT' – AJM 2010-06-02 14:35:55