I am trying to run an XMLA command that kicks off an Xevent trace as a SQL Agent Job. (below)
The command works fine in SSMS as an XMLA query.
When I try to save this step as an SSAS Command in an agent job, it throws an exception -
An exception occurred while executing a Transact-SQL statement or batch.
(Microsoft.SQLServer.Connectioninfo)The @flags parameter is not valid for a job step of type 'ANALYSISCOMMAND'. (Microsoft SQL Server,Error: 14545)
This job step can be saved as TSQL but it will return a syntax error - as it should - when I invoke it.
I have no experience creating agent jobs using xmla code.
<Create xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <ObjectDefinition>
<Trace>
<AutoRestart>true</AutoRestart>
<ID>BostonWeekendTest</ID>
<Name>BostonWeekendTest</Name>
<XEvent xmlns="http://schemas.microsoft.com/analysisservices/2011/engine/300/300">
<event_session name="BostonWeekendTest" dispatchLatency="30" maxEventSize="0" maxMemory="4" memoryPartition="none" eventRetentionMode="NoEventLoss" trackCausality="true" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<event package="AS" name="QueryBegin" />
<event package="AS" name="QuerySubcubeVerbose" />
<event package="AS" name="ExecuteMDXScriptEnd" />
<target package="package0" name="event_file">
<parameter name="filename" value="J:\XEvents\BostonWeekendTest.xel" />
<parameter name="max_file_size" value="4096" />
<parameter name="max_rollover_files" value="10" />
<parameter name="increment" value="1024" />
</target>
</event_session>
</XEvent>
</Trace> </ObjectDefinition> </Create>
The latest SSMS with SQL Server agent on SQL 2019 CU 16 successfully created the job for me. The @flags
parameter is on sp_add_jobstep, so compare to what your SSMS is generating.
Here's the job creation script (with the path modified):
USE [msdb]
GO
/****** Object: Job [xmla] Script Date: 9/17/2022 12:10:06 PM ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object: JobCategory [[Uncategorized (Local)]] Script Date: 9/17/2022 12:10:06 PM ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
END
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'xmla',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'No description available.',
@category_name=N'[Uncategorized (Local)]',
@owner_login_name=N'OFFICE\david', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [a] Script Date: 9/17/2022 12:10:06 PM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'a',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'ANALYSISCOMMAND',
@command=N'<Create xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <ObjectDefinition>
<Trace>
<AutoRestart>true</AutoRestart>
<ID>BostonWeekendTest</ID>
<Name>BostonWeekendTest</Name>
<XEvent xmlns="http://schemas.microsoft.com/analysisservices/2011/engine/300/300">
<event_session name="BostonWeekendTest" dispatchLatency="30" maxEventSize="0" maxMemory="4" memoryPartition="none" eventRetentionMode="NoEventLoss" trackCausality="true" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<event package="AS" name="QueryBegin" />
<event package="AS" name="QuerySubcubeVerbose" />
<event package="AS" name="ExecuteMDXScriptEnd" />
<target package="package0" name="event_file">
<parameter name="filename" value="c:\temp\BostonWeekendTest.xel" />
<parameter name="max_file_size" value="4096" />
<parameter name="max_rollover_files" value="10" />
<parameter name="increment" value="1024" />
</target>
</event_session>
</XEvent>
</Trace> </ObjectDefinition> </Create>',
@server=N'office\sql2022',
@database_name=N'master',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO