扩展事件会话未捕获SQL文本

时间:2019-05-06 09:22:38

标签: azure-sql-database extended-events

我在我的azure sql数据库上创建了一个扩展事件会话,以捕获存储过程和sql语句。问题是会话中没有捕获来自Web应用程序的任何活动。但是,从SSMS运行的所有查询都会在会话中捕获。我的目标是捕获带有参数的存储过程执行。

CREATE EVENT SESSION VG
ON DATABASE

ADD EVENT sqlserver.sql_statement_completed
( ACTION (sqlserver.sql_text,sqlserver.database_name)),
ADD EVENT sqlserver.rpc_Completed
 ( ACTION (sqlserver.sql_text,sqlserver.database_name)),
 ADD EVENT sqlserver.module_end
 ( ACTION (sqlserver.sql_text,sqlserver.database_name))
ADD TARGET package0.ring_buffer
(SET max_memory = 500, max_events_limit = 10000 )
;

ALTER EVENT SESSION VG
ON DATABASE
STATE = START;

DECLARE @ShredMe XML;
SELECT @ShredMe = CAST(target_data AS XML)
FROM sys.dm_xe_database_sessions  AS s
JOIN sys.dm_xe_database_session_targets AS t
ON t.event_session_address  = s.address
WHERE s.name = N'vg';

SELECT
QP.value('(data[@name="statement"]/value)[1]', 'varchar(max)') as [SQL CODE],
QP.value('(action[@name="database_name"]/value)[1]', 'varchar(max)') as [Database],
QP.value('(@timestamp)[1]', 'datetime2') AS [timestamp]

FROM @ShredMe.nodes('RingBufferTarget/event[@name=''sql_statement_completed'']') AS q(QP);
GO

0 个答案:

没有答案