Dynamics Ax ‘SqlStatementExecutePermission’ failed

If you are running native SQL statements in Ax, you might see below error while executing code.

Request for the permission of type ‘SqlStatementExecutePermission’ failed.
(C)JobsRahAddressImport – line 76

Code snippet you might be using:

    sqlQ = “Select * From CustTable”;

    // Set code access permission to help protect the use of
    // Statement.executeUpdate.
    perm = new SqlStatementExecutePermission(sqlQ);
    perm.assert();//should run on server

        // BP deviation documented
        rs = cmd.executeQuery(sqlQ);//will throw error
        while (rs.next())
            //process records            

This only means that your code is running on client side. You must call the assert method in your code on the same tier, usually the server tier, that the corresponding CodeAccessPermission::demand method is called on before the protected API is executed. Call a method on the server tier from one of the following:

  • A server static method


  • A class instance method that is set to run on the server by using the RunOn class property

Feel free to post any comment / feedback here.

If you liked the story and want to see more of this kind of content, please follow our twitter handle @CursorRun or FB page @CursorRun
Default image
Rahul Sharma
Rahul is a technology enthusiast, solutions architect, trainer, and blogger, working on various Microsoft and open source solutions with more than 18 years of industry experience. He specially takes interest in designing enterprise applications, cloud integrations, IoT, and other architecture rich business solutions. Rahul is a guest author with us and shares his knowledge through technology blog posts.
Articles: 59


Enter your email address below to subscribe to our website. We will never flood your inbox with unwanted emails & you can always unsubscribe anytime.

Leave a Reply