Rahul Sharma

Solutions Architect - Microsoft Dynamics AX | Azure

This is a technology blog covering Microsoft Dynamics 365, Microsoft Azure, IoT, Power Apps, Power BI, .Net, SQL Server, SSRS, and related technologies. Join this blog on facebook {Rahul Sharma}, to start a discussion !!! NOTE: My employer is not responsible for the content published here.

Index | MS Dynamics AX | MS Dynamics CRM
View blog as >> Magazine | Sidebar | Flipcard | Mosaic | Snapshot | Timeslide

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)\Jobs\RahAddressImport - 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.