Sunday, March 29, 2015

Executing a Stored Procedure from AX


I am not really a fan of having external code supporting functionality within Dynamics AX, but there may come a time when for whatever reason you need to create a stored procedure and have it executed from XPP code.

server static void executeSP()
{
    Connection con = new Connection();
    Statement stmt = con.createStatement();
    ResultSet r;
    str sql;
    SqlStatementExecutePermission perm;
    ;
    sql = strfmt('EXEC [insertdaxjob]');
    perm = new SqlStatementExecutePermission(sql);
    perm.assert();
    try
    {
        stmt.executeUpdate(sql);
    }
    catch (exception::Error)
    {
        print "An error occured in the query.";
        pause;
    }
    CodeAccessPermission::revertAssert();
}

No comments: