
IF EXISTS(
    SELECT *
    FROM sys.dm_xe_sessions s
    WHERE s.name = 'tsc_octpdba-512'
)
BEGIN 
    ALTER EVENT SESSION [tsc_octpdba-512] ON SERVER STATE = STOP;
END

IF EXISTS(
    SELECT *
    FROM sys.server_event_sessions s
    WHERE s.name = 'tsc_octpdba-512'
)
BEGIN 
    DROP EVENT SESSION [tsc_octpdba-512] ON SERVER;
END 
GO



CREATE EVENT SESSION [tsc_octpdba-512] ON SERVER 
ADD EVENT sqlserver.connectivity_ring_buffer_recorded(
    ACTION(package0.last_error,sqlserver.client_app_name,sqlserver.client_connection_id,sqlserver.client_hostname,sqlserver.context_info,sqlserver.server_principal_name,sqlserver.session_id)),
ADD EVENT sqlserver.dtc_transaction(
    ACTION(package0.last_error,sqlserver.client_app_name,sqlserver.client_hostname)),
ADD EVENT sqlserver.errorlog_written(
    ACTION(package0.last_error,sqlserver.client_app_name,sqlserver.client_hostname)),
ADD EVENT sqlserver.login(SET collect_options_text=(1)
    ACTION(package0.last_error,sqlserver.client_app_name,sqlserver.client_connection_id,sqlserver.client_hostname,sqlserver.context_info,sqlserver.server_instance_name,sqlserver.server_principal_name)),
ADD EVENT sqlserver.logout(
    ACTION(package0.last_error,sqlserver.client_app_name,sqlserver.client_connection_id,sqlserver.client_hostname,sqlserver.context_info,sqlserver.server_instance_name,sqlserver.server_principal_name,sqlserver.session_id))
ADD TARGET package0.event_file(SET filename=N'd:\tsc_octpdba-512')
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=ON,STARTUP_STATE=ON)
GO

ALTER EVENT SESSION [tsc_octpdba-512] ON SERVER STATE = START;
