Question

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

Menu Item

Was it helpful?

Solution

I should have given my comment as an answer but wasn't paying attention:

Try server static void Trigger... and perhaps statement.executeUpdate(...) instead of executeQuery

OTHER TIPS

Calling EXEC from executeQuery is not supported.

See this question:

How to get the results of a direct SQL call to a stored procedure?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top