Search code examples
sql-server-2012extended-events

How can I schedule an extended event to run at a specific time


Basically I have created a new extended event session, and I want to schedule this to run for a specific time lets say 2:00 AM. Usually I would of written a script to create a trace and then been able to schedule it using SQL Agent as a job, but I'm new to using Extended Events and I would want to know how I can schedule a session to start capturing at a specific time.


Solution

  • You can create the session at any moment using CREATE EVENT SESSION: this will only create the session, but won't start it. In your SQL Agent job you can start the session according to your schedule using this simple command:

    ALTER EVENT SESSION session_name
    ON SERVER
    STATE = start;