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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans