• Haidong,

    You are right in your sense, I think we are just not in the same page for the same question, my original concern is :

    if you put the sp in a job and configure it as "Start automatically when SQL Server Agent starts", then what happen if you only restart the Agent without restarting the SQL Server ? I am afraid we may create multiple trace in the system.

    And you actually give me the answer by saying:

    Yes, you are able to stop and restart SQL Agent without affecting SQL Server service. I don't have time to test that scenario, but I would agree that the existing trace would still be active, if it is not timed out or stopped manually.

    And i test it today, it did keeping create new active trace in the system each time you stop and start Agent service, i fixed this simply put the following the first line inside the SP:

    IF EXISTS (select * from ::fn_trace_getinfo(0) where property=5 and value=1) Return

    But be aware of the fact, this assume you have only one active trace on the server, and it's true in my system.

    Just wanna share this with you, again, thank you for your help, it's great script.

    ddfg