Rahul Sharma

Solutions Architect - Microsoft Dynamics AX | Azure

Blog
This is a technology blog covering Microsoft Dynamics AX, Microsoft Dynamics CRM, Microsoft Azure, IoT, .Net, SharePoint, SQL Server, SSRS, SSAS, SSIS, Apache Cassandra, MongoDB, 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.
(S)\Classes\SqlStatementExecutePermission\demand
(S)\Classes\Statement\executeQuery
(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

    try
    {
        // 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
-or-
  • 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.
Comments
0 Comments