SQL Server 2012 :: Using Xquery To Get Event Data Back From Extended Events?

Feb 25, 2014

I am trying to use xquery to get event data back from extended events. I am trying to use some sample data from Grant Fritchey but I am getting null records back. Below is the xml - I just want to retrieve a distinct list of the client_hostname and client_app_name.

<event name="login" package="sqlserver" timestamp="2014-02-19T23:53:54.299Z">
<data name="is_cached"><value>true</value></data><data name="is_dac">
<value>false</value></data><data name="database_id"><value>7</value>
</data><data name="packet_size"><value>8000</value></data><data name="options">

[Code] ....

The query I have that doesn't work is :

WITH xEvents AS
(SELECT object_name AS xEventName,
CAST (event_data AS xml) AS xEventData
FROM sys.fn_xe_file_target_read_file
('C:LoginTraceShared_0*.xel', NULL, NULL, NULL))
SELECT distinct top 1000 xEventName,
xEventData.value('(/event/data[@action_name=''Client_APP_Name'']/value)[1]','varchar') Client_APP_Name,
xEventData.value('(/event/data[@action_name=''Client_Host_Name'']/value)[1]','varchar') Client_Host_Name
FROM xEvents

View 3 Replies


ADVERTISEMENT

SQL Server 2012 :: Right Way To Query Extended Events Session?

Jun 4, 2015

I use this code in a utility procedure (for performance testing) but it is really slow.

For example, a session with three events is taking 5 seconds to complete this query:

DECLARE @xml xml=
(
SELECT CAST(xet.target_data AS xml)
FROM sys.dm_xe_session_targets AS xet
JOIN sys.dm_xe_sessions AS xe
ON (xe.address = xet.event_session_address)
WHERE xe.name = @name
);

with data as

(
select
convert(varchar(128),convert(varbinary(128),'0x'+n.value('(action[@name="context_info"]/value/text())[1]','varchar(128)'),1)) context
, n.value('(data[@name="duration"]/value/text())[1]','int')/1000.0 duration
, n.value('(data[@name="cpu_time"]/value/text())[1]','bigint')/1000.0 cpu_time
, n.value('(data[@name="physical_reads"]/value/text())[1]','bigint') physical_reads

[code].....

So, I was wondering (considering the buffer is usually only holding a few hundred events)

1. Is this the wrong way to query data from a ring buffer?

2. Is there any way to make this code quicker?

3. Is it better to target a file store rather than a ring buffer for this?

select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003D
D8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000

[Code] .....

View 6 Replies View Related

DB Engine :: How To Add Execution Plan To Extended Events Results Also When Capturing Deadlock Event

Oct 24, 2015

We know we can use the event lock_deadlock and xml_deadlock_report to capture the deadlock info,  however I also want to capture the execution plans for all of the SPIDs in the deadlock graph,  how to output the execution plans to the extended events trace results either ? such as if there is an action for execution plan or workaround for it ?If there is no built in action for execution plan , may I know if we can add the customized info to the extended events results file also ? Such as when the deadlock related event happens , then we can run a query to get some info ,then added the info along with other info such as sql_text, dbname  etc  to the events trace results file either ? The reason is if we also know the execution plans when the deadlock happens, it is useful to turning the query based on the execution plans to reduce deadlock happening .

View 5 Replies View Related

Transact SQL :: Convert Or Change All Existing Traces To Extended Events In Server 2012

May 27, 2015

We are planning to convert or change all existing Traces to Extended Events in SQL server 2012. What is the procedure to convert custom traces. We have already created some below custom traces: like this we are planning to convert for all servers.

exec sp_trace_setevent @TraceID, 20, 23, @on
exec sp_trace_setevent @TraceID, 20, 8, @on
exec sp_trace_setevent @TraceID, 20, 12, @on
exec sp_trace_setevent @TraceID, 20, 64, @on
exec sp_trace_setevent @TraceID, 20, 1, @on
exec sp_trace_setevent @TraceID, 20, 21, @on

[code]...

View 6 Replies View Related

SQL 2012 :: Extended Events For Deadlock?

Oct 6, 2014

I've setup a deadlock monitor using extended events like this.

CREATE EVENT SESSION [deadlock] ON SERVER
ADD EVENT sqlserver.lock_deadlock(
ACTION(package0.process_id,sqlserver.client_app_name,sqlserver.client_hostname,
sqlserver.database_id,sqlserver.database_name,sqlserver.plan_handle)

[Code] ....

Deadlock happened couple of days ago. I'm trying to determine the cause of deadlocks. What script should I use to pull that information to see what objects/processes caused deadlock?

View 8 Replies View Related

SQL 2012 :: Extended Events And Client IP Address

Jan 14, 2015

I want to gather (and filter by) client ip address in an extended events session. So far, I have the sqlserver.login event added, but I can find no way to get client ip address added to the action or predicate.

I can filter by the pred_source field "session_nt_domain" or "nt_domain" but this is not always populated by all logins and also, this domain only lists machine name, such as FRED, as opposed to the full domain FRED.foo.bar.

Is it possible to gather login client ip address in an extended events session? Surely internal SQL Server processes have access to it because the login audit can populate client ip address.

View 1 Replies View Related

SQL 2012 :: Capturing Errors And RPC Completed With Extended Events

Jun 17, 2014

I have an existing EE setup that captures all failing queries (see code below). The problem is that I also want to somehow capture RPC_starting so that I can see which parameters are passed in whenever a query fails. Is there a way to somehow capture those two events (error_reported & rpc_starting), but only capture rpc_starting when there is actually an error reported?Or maybe just an event on rpc_starting and somehow filter to only capture when there is an error?

Existing error_reported EE code:
CREATE EVENT SESSION [what_queries_are_failing] ON SERVER ADD EVENT sqlserver.error_reported (
ACTION(sqlserver.sql_text, sqlserver.tsql_stack, sqlserver.database_id, sqlserver.session_id,
package0.collect_system_time, sqlserver.transaction_id, sqlserver.username, sqlserver.client_hostname)

[code]....

View 6 Replies View Related

SQL 2012 :: Extended Events Capturing Info On Dev Environment But Not On PRO?

Jan 27, 2015

I do have the following Extended Event session on my Dev box;

CREATE EVENT SESSION [sp_showplan] ON SERVER
ADD EVENT sqlserver.query_post_execution_showplan(SET collect_database_name=(1)
ACTION(sqlserver.plan_handle)
WHERE ([package0].[equal_uint64]([object_type],(8272)) AND [sqlserver].[equal_i_sql_unicode_string]([object_name],N'MyStoreProcedure')))
ADD TARGET package0.event_file(SET filename=N'E:DBA_AuditSP_Exec.xel',metadatafile=N'E:DBA_AuditSP_Exec.xem')
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)
GO

The idea is being able to capture the execution plan when the program invokes the store procedure, regardless of the database.

This works on my Dev box. When I manually trigger "MyStoreProcedure" from database A , the event is saved. The same thing happens when I do that from database B. Ok ... so far, so good.

So I went to the live production environment and setup my Extended Events session. But it's saving nothing. I was able to check that the store procedure was executed on several databases but my extended events session never grabbed the plan.

What could be the reason for this? Memory starvation maybe? Is there something I am doing wrong?

View 5 Replies View Related

SQL 2012 :: Extended Events Duration In Milliseconds Or Microseconds?

Apr 15, 2015

When you view the Extended Events "Watch Live Data" is the duration in milliseconds or microseconds? I'm assuming it's milliseconds, but if you look at the timestamp difference from start to complete it doesn't add up to the duration amount? It looks like it's just the difference between the timestamps?

View 5 Replies View Related

SQL 2012 :: Can Combine Performance Monitor Counters With Extended Events

Oct 14, 2014

In the past, I've combined server side traces with Perfmon successfully, which is pretty useful, I know that. I would like to do the same with Extended Events, so I can correlate and analyze the server side as well.

View 4 Replies View Related

SQL 2012 :: Extended Events And Wait Stats For Specific Session

Mar 4, 2015

I wanted to demonstrate something about CXPACKET wait type. For the purpose of this demo I've created a query in AdventureWorks database that uses a parallel query plan, an extended events session that captured the wait statistics for a single session and a query that shows the extended event's data. I ran it and it worked fine. Then I dropped and recreated the event session (to clear the data), in a new window I wrote a transaction that updated the table fallowed by waitfor statement so the first query will be blocked for few seconds and ran the whole thing again. The select statement was blocked as expected (ran for 9 seconds instead on 1 second as it ran without the blocking), but the wait stats that I got were almost identical to the those that I got without blocking the query.

--Query that uses parallel query plan
With MyCTE as (
select top 50 * from Sales.SalesOrderHeader)
select top 10000 * from Sales.SalesOrderHeader, MyCTE
order by newid()

[code]....

View 1 Replies View Related

Transact SQL :: Emailing Session Events For Extended Events

Feb 3, 2014

I am using this code for LongRunning Queries.

CREATE EVENT SESSION LongRunningQuery
ON SERVER
ADD EVENT sqlserver.sql_statement_completed
(
ACTION (sqlserver.sql_text, sqlserver.tsql_stack)
WHERE sqlserver.sql_statement_completed.duration > 60000

[Code] ...

Here Instead of writing to XML file how can send an EMAIL if a query runs more than 1 minute in my server ?

View 2 Replies View Related

SQL 2012 :: Capturing Historic Deadlock Using Extended Event

Dec 9, 2014

I am learning Extended event to capture deadlock which already happened, for this in my SQL SERVER 2012.. I am simulating a deadlock . With [URL]... where given a query to find the deadlock details using extended event here is the code..Retrieve from Extended Events in 2012.

SELECT XEvent.query('(event/data/value/deadlock)[1]') AS DeadlockGraph
FROM ( SELECT XEvent.query('.') AS XEvent
FROM ( SELECT CAST(target_data AS XML) AS TargetData
FROM sys.dm_xe_session_targets st
JOIN sys.dm_xe_sessions s

[code]...

This code creates a deadlock but when i run the above Extended events query to get the details of deadlock, it doesnot display any results.

View 4 Replies View Related

SQL Tools :: Not Able To Clear Data Within Session Of Extended Events Unlike Trace

Nov 10, 2015

I have created a session in extended events and want to frequently monitor the events that i have filtered .The problem i am facing is i am not able to clear the previous data as we do it in SQL trace. i am able to see all the data that is occupied till now.whenever i start the test i want the current data only to be displayed.The work around is either delete the session and create a new one every-time which i do not want to do .I am able to see the CLEAR DATA FROM TABLE button but it is in Disabled state all the time.

View 2 Replies View Related

SQL Server Admin 2014 :: Duration In Extended Events

Jun 11, 2015

I am wanting to get/filter on all queries and procs that take longer than 2 seconds to run (I'll balance real values later) but I'm not sure which Action out of the XE that I need.

I am using SQL Server 2014 and thought I had used sqlserver.sql_statement_completed.duration > 2000 in a previous version.

View 5 Replies View Related

Recovery :: Configure Extended Event To Trigger A Mail Whenever Any Event Occurs

Jun 2, 2015

Recently we migrated our environment to 2012.

We are planning to implement Xevents in all the servers in place of Trace files and everything is working fine.

Is it possible to configure Extended event to trigger a mail whenever any event (example dead lock) occurs.

I have gone through so many websites but i never find.

View 13 Replies View Related

SQL Server 2008 :: Extended Events Capture A Specific Proc Parameter

Feb 19, 2015

I know very little about Extended Events, but I know it is supposed to be more powerful than Profiler. The SQL Instance involved is 2008R2. I was asked whether we could capture when a stored proc was called with a certain parameter. So for example, if dbo.usp_mystoredproc is called and is passed a value of '12345a' for @customer, can that be captured? I would want to know the time it was called, the parameter and parameter value. Probably would be interested in the SPID or LoginName as well.

View 4 Replies View Related

SQL Server Admin 2014 :: Gathering Results From Extended Events Trace

Jun 16, 2015

I need to find any stored procedures that have not been used over a certain time period.

I have set up an extended events session to gather sp_statement_starting and _completed.

The trace returns the object_id's of many stored procedures. I then query the sys.procedures and plug in the object_id to return the stored proc name.

Do I have to repeat this process for every different object_id or is there a way I can query the trace results, using the object_id as my search criteria as one query ?

View 9 Replies View Related

SQL Server Admin 2014 :: How To Read And Load Extended Events Into A Table For Querying

Jun 19, 2015

I am setting up extended events more or less just fine, however I am a bit confused as to how to read and load them into a table for querying. In particular the offset part - is there a way to load just a given dates worth in?

I've got the files configured to be 20MB before rolling over, the XE is running all the time.

So if i load in the full file now, say that covers 2.5 days worth, when I load it again tomorrow to get the updated data I'm also reloading today, which is a waste?

I presume I am going about this wrong, but lack an example that really goes into detail of practicalities of loading this data.

View 0 Replies View Related

SQL Server Events Logged In As Windows Application Event

Jul 10, 2003

Hello Everyone,

I am backing up my all the databases (around 50 servers and 500 database) using scheduled jobs. I backup my transaction log files at every two hours of interval and databases on daily basis.

I have set option of "Write to Windows Application Event Log" - When job fails during the creation of job in the "Notification Tab" of Create New Job.

As per documentation SQL server automatically records some of the events to windows application event log. After succesful completion of Log backup and DB backup, event gets logged in Windows Application Event Log. And when job fails, I get two events logged in the Windows Application Event Log file, one due to my setting and other automatically by SQL Server.

Due to this Windows event log file is growing much faster and I have to clear it in every 3-4 days.

My quesiton - Is there a way such that to get only failures event logged in Windows Application event log file and any successful backup jobs should not go to Windows application event file?

Can any suggest some idea what should I do?

I am using SQL Server 2000 with SP3 on Windows 2000 Advanced server. Some of my databases are still using Version 7.0/6.5 on NT.

Thanks.

View 5 Replies View Related

DB Engine :: Cannot Stop Extended Event Session On Server

Jan 25, 2012

I have two extended events sessions running on a server. I do have sql jobs that automatically stop the XE sessions and import the results to working tables. I see two "ALTER EVENT SESSION XXXX ON SERVER STATE = STOP" statements that are being executed for more than 2 days, the wait types are XE_SERVICES_MUTEX and PREEMPTIVE_XE_SESSIONCOMMIT. This is not the first time I see this behavior.I do not want to kill the sessions (I guess the sessions won't die anyway) neither restart the sql service

View 7 Replies View Related

Extended Events With Pair Matching

Oct 12, 2015

I can only do one match at a time -- Like can only do either the sql_statement_(start and end), or sp_statement_(start or end). Is there any way to capture both in the same session? Or since I am adding both the events in the ADD EVENT section, can I query it somehow to get unmatched SP or SQL?

Code:

USE master;
GO
-- Create the Event Session
IF EXISTS(SELECT *
FROM sys.server_event_sessions
WHERE name='TimedOutSQL')

[code]...

View 2 Replies View Related

SQL Server 2012 :: Where To Find List Of Values For Event Data Files

Jan 21, 2015

Got following query:

SELECT
event_data.value('(event/data/value)[4]', 'bigint') AS cpu_time,
--database name
event_data.value('(event/data/value)[5]', 'bigint') AS duration,
--estimated cost
--estimated rows
--nest level

[code]...

Basically, is a simple T-SQL query that reads the local file for my already setup extended event sessions. But I can't find the way to retrieve the following attributes as part as the T-SQL query:

--database name
--estimated cost
--estimated rows
--nest level
--object name

I am trying to find a BOL or some MS link with the full list of possible values for event_data.value but can't find one.

View 2 Replies View Related

Transact SQL :: Get Duration Of Each Event 0 Which Has Other Events Before And After?

Jun 22, 2015

I have a table that holds log event records, that keep getting appended. I need to get the duration of the each event 0 which has other events before and after. How can I do this - to get event duration of event 0 and the cumulative.

ID Event   Date
1    1        2015-06-21 21:01:44.457
2    1        2015-06-21 21:01:44.457
3    0        2015-06-21 21:02:04.780
4    1        2015-06-21 21:02:32.600
5    0        2015-06-21 21:02:57.967
6    1        2015-06-21 21:03:30.513

View 7 Replies View Related

Log Events Is Interrelated With Event Viewer Windows?

Dec 11, 2006

Hi everyone,
I was wondering how do for 'Log Events' info going to Event Viewer Windows visor. Is it possible or it's just only private info for you SSIS.

Thanks for your input,

View 2 Replies View Related

Custom Events While Retaining Original Event Arguments (SqlDataSourceStatusEventArgs)

Dec 26, 2007

Hi,
I am looking to implement a custom event handler that will also retain the original event arguments (in addition to several custom arguments).
Specifically, I am looking to pass custom arguments into a SqlDataSourceStatusEventHandler, but also want to be able to access the Command.Parameters.
I have implemented a new Event Arguments class (derived from System.EventArgs), new Event class and delegate, but do not know how to retain the SqlDataSourceEventArgs. I would really appreciate your suggestions!
Thanks!
 

View 2 Replies View Related

SQLISPackage Start/finish Events In Windows Event Logs

Mar 1, 2007

I was wondering if anyone knew of a way to disable the following, SQLISPackage start/finish events sent to windows event logs everytime a SSIS package is executed and completed.

Regards

Ryan Dickson

View 1 Replies View Related

SQL 2012 :: XQuery Delete From XML Variable

Nov 20, 2014

I'd like to delete A3 from the XML variable below, however I get "XQuery [modify()]: The XQuery syntax '/function()' is not supported."

DECLARE @XML XML = '<Attribute>
<A1>6529</A1>
<A2>6529</A2>
<A3>6529</A3>
</Attribute>'

DECLARE @n VARCHAR(100) = 'A3'

SET @XML.modify('delete (/Attribute/sql:variable("@n")[1]) ')
SELECT @XML

View 3 Replies View Related

SQL Server Error Logs: What Events Is It Logging? Can We Edit And Include DDL Events?

Jun 20, 2007

Hello experts. I have been searching for anything about this but found very little. What are the events logged in SQL Server Error Logs aside from Successful/Failed Login, Backup/Restore/Recover database and, start/init sql server? Can we configure this to log other events, like CREATE or DBCC events for example? If so, how? Thanks a lot.

View 1 Replies View Related

Query Data From XML Column With XQuery

Jan 22, 2013

I am trying to learn XQuery and Xpath in SQL Server. I created a sample file and uploaded it to a Table with 2 columns ID, XMLDoc. The below code is within the document in the XMLDoc column so it is the only record in the column.

I am trying to query the file so it will show all the results in a table like a normal select statement would. How would you construct the select statement to select all the information like a select * ? How would you select one field like all suppliers? I would like to select the supplier, requestor for each item.

Here is the xml:

Code:
<tst:Document xmlns:tst ="http://www.w3.org/2001/XMLSchema" SchemaVersion="0.1" Classification="Test" UniqueIdentifier="1234" Title="Test">
<tst:Revision RevNumber="0" TimeStamp="2013-01-21T12:56:00">
<tst:Author Name="Me" Guid="1234" />
</tst:Revision>

[Code] ....

View 1 Replies View Related

SQL Server 2012 :: Capture Statement From Missing Join Predicate Event?

Jan 27, 2015

After monitoring using SQL profiler, i found that Missing join predicate event is happening a lot.

The problem is that profiler doesn't allow me to select the textdata to know which SQL statement is causing the issue.

I tried using the spid to check what's that process is running but the problem is that application is running many sqls so when i run

select PROGRAM_NAME,hostname,qt.text from sys.sysprocesses as sps1 CROSS APPLY sys.dm_exec_sql_text(sps1.sql_handle) AS qt
where spid=169

it gets me the SQL being run at that time not the one that causing the event.

View 3 Replies View Related

SQL Server 2012 :: If Minus Figure Pull Back 0

Feb 6, 2015

Have the following in my SELECT Stataement

CASE WHEN com.completion_date IS NOT NULL AND dim.DayName <> 'Saturday'
THEN DATEDIFF(d, com.current_task_target_date,com.completion_date) - non1.NoWorkDays
WHEN com.completion_date IS NOT NULL AND dim.DayName = 'Saturday'
THEN DATEDIFF(d, com.current_task_target_date,com.completion_date)
ELSE NULL
END AS 'DaysOverTarget'

Some of the figures coming back are minus figures. How could I get the minus figures reported to be 0.00?

Below is the full TSQL

SELECT DISTINCT com.comm_reference AS 'Referance'
,com.crt_date AS 'CreatedDate'
,com.current_task_target_date AS 'TargetDate'
,com.completion_date AS 'CompletionDate'
,CASE WHEN com.completion_date IS NOT NULL AND dim.DayName <> 'Saturday'
THEN DATEDIFF(d, com.crt_date,com.completion_date) - non.NoWorkDays

[Code] .....

View 4 Replies View Related

SQL Server 2012 :: View To Concatenate File / Path Names Back To Root Directory?

Sep 25, 2014

We have a hierarchical table of some 2-3k of rows that grows slowly at only 3-5 rows a month, and is never likely to be above 5k, holding file/directory names with an IdParent int value pointing at that items immediate parent or NULL if root

Below is a sample:

Id Name IdParent
1 C: NULL
2 D: NULL
3 ProgramFiles 1
4 DataFiles 2
5 Excel.EXE 3
6 MyDataList.CSV 4

iterative code required to achieve the result I am looking for is best handled in the Application layer, but in this case the design brief is that we must get our results back as a View. Speed of execution and code clarity are secondary 'icing on the cake' issues.

I have tried recursive CTE's and XML FOR solutions but without success, and while I feel the latter is probably the best all rounder the searches I have made and the examples I have read do not seem to solve this particular issue.

Even to find the starting point of the search tree (i.e. the .EXE and the .CSV items) was difficult because the final slash is optional in some of the rows (.e. row 4)

The end result of my view on the above data should return:

Id FilePath
5 C:ProgramFilesExcel.EXE
6 D:DataFilesMyDataList.CSV (note the adding of the missing delimiter between DataFiles and MyDataList)

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved