I want to trigger an SQL job which runs an SSIS package from an AX Job, I successfully ran SQL code fetching some records from an SQL table by creating a menu item for the job and have it run on the server instead of the client but the following code runs without errors but the Job's not started?
CODE:
static void TriggerAllocation(Args _args)
{
UserConnection userConnection;
Statement statement;
str sqlStatement;
SqlSystem sqlSystem;
SqlStatementExecutePermission sqlPermission;
;
sqlSystem = new SqlSystem();
sqlStatement = "EXEC MSDB.dbo.sp_start_job @Job_Name = 'MyJob'";
userConnection = new UserConnection();
statement = userConnection.createStatement();
sqlPermission = new SqlStatementExecutePermission(
sqlStatement);
sqlPermission.assert();
statement.executeQuery(sqlStatement);
CodeAccessPermission::revertAssert();
I can't find any more clues in e.g. eventviewer, SQL logs as for what went wrong..
Kind regards,
Mike
[UPDATE] Thanks to Alex K I solved it!
using
statement.executeUpdate(sqlStatement);
instead of
statement.executeQuery(sqlStatement);
did the trick!
Keep in mind that running the job directly from AX won't work despite: server static void You'll have to create an Menu Item of type action with property RunOn=Server