web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

InteropPermission Error in calling a stored procedure from AX 2009

(0) ShareShare
ReportReport
Posted on by 475

Hi.

Actually our requirement is to know the pending Purchase Requisitions(PR's). i mean we want a report so that we can know like with which user and since which date the PR is pending.

So i wrote a stored procedure in SQL which does this task. This Stored procedure shows me all i require.

Basically i want to publish this Stored procedure in AX  client to the users so that they can track the pending PR's.

 So i want to call this stored procedure from AX.

I created a class then put my code inside it and assigned it to a menu item. Currently i am displaying the output in "Info". But i want to display my output as a report .

so for this i created a temperary table and trying to insert the records fetched from that stored procedure and later use that temp table and design a report. But i am getting a error.

 Below is my code :

 server static client void executeQuery()
{
    System.Exception netExcepn;
    Connection con = new Connection();
    Statement stmt = con.createStatement();
    ResultSet r;
    str sql;
    SqlStatementExecutePermission perm;

    int iCount;
    str resultString;
    TmpPRStatus  TmpPRStatus;

;

     sql = strfmt('EXEC  dbo.EMI_PRTrackPendingCases');    // My stored procedure Name
       perm = new SqlStatementExecutePermission(sql);
        perm.assert();

   try
   {
        R = stmt.executeQuery(sql);
        while ( R.next() )
            {

                 resultString = strfmt(' %1   : %2:    %3:    %4:    %5:    %6: %7  \n ',
                                                      R.getString(1),
                                                      R.getString(2),
                                                      R.getString(3),
                                                      R.getString(4),
                                                      R.getString(5),
                                                      R.getString(6),
                                                      R.getString(7));

                setprefix('Pending Purchase Requisition');
                info( resultString);
              
               ttsbegin;

                 while select forupdate  TmpPRStatus
                 {
                    TmpPRStatus.Originator    = R.getString(1);
                    TmpPRStatus.PendingWith   = R.getString(2);
                    TmpPRStatus.PurchReqId    = R.getString(3);
                    TmpPRStatus.Description   = R.getString(4);
                    TmpPRStatus.SubmittedDate = R.getString(5);
                    TmpPRStatus.PendingSince  = R.getString(3);

                 }
                    TmpPRStatus.insert();
                    ttscommit;
                   }

  }
    catch (exception::Error)
    {
        netExcepn = CLRInterop::getLastException();
        print "An error occured in the query.";
        pause;
  }
 CodeAccessPermission::revertAssert();

}

 

when i run the above code i get this below error.

Request for the permission of type 'InteropPermission' failed.
(S)\Classes\InteropPermission\demand
(S)\Classes\CLRInterop\getLastException

Please Guide me with this error.

Thanks.

*This post is locked for comments

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans