Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
1,Sys.dm_exec_connections:返回与SQL SERVER实例建立的连接的相关信息。
2,Sys.dm_exec_sessions:当前执行的会话,如查询分析器窗口就是一个会话
3,Sys.dm_exec_requests:正在执行或处于等待状态的请求。
流程:connection->session->request
SELECT DB_NAME(r.database_id) DB,
substring(qt.text,r.statement_start_offset/2,
(case when r.statement_end_offset = -1
then len(convert(nvarchar(max), qt.text)) * 2
else r.statement_end_offset end -r.statement_start_offset)/2
) as ‘SQL statement’,
qt.text batch,s.status,c.client_net_address,s.login_name, s.program_name,s.host_name,
s.login_time,c.connect_time,s.last_request_start_time, s.last_request_end_time,s.session_id,
s.host_process_id, s.client_version, s.client_interface_name,c.net_transport, c.net_packet_size,
r.request_id, r.start_time, r.status, r.command, r.user_id, r.blocking_session_id, r.wait_type,r.wait_time,
r.last_wait_type, r.wait_resource, r.open_transaction_count,r.transaction_id, r.percent_complete, r.cpu_time, r.reads, r.writes,r.granted_query_memory
FROM Sys.dm_exec_connections c
LEFT JOIN Sys.dm_exec_sessions s ON c.session_id = s.session_id
LEFT JOIN Sys.dm_exec_requests r ON s.session_id = r.session_id
outer apply sys.dm_exec_sql_text(r.sql_handle) as qt
ORDER BY c.client_net_address,s.login_name