Call SQL stored procedure from Ax client

Hello,

Can anyone send me the code to call SQL SP in dynamics Ax client?

I had tried all examples available on internet, but facing connection problem.

HELPPPPPPPPP

Abhishek

For example, take a look at this one:

http://www.geekpedia.com/Thread29003_Microsoft-Dynamics-AX-40-And-Stored-Procedures.html

But what connection problems do you have?? Are you trying to call the same named procedure which you copied from example and which most likely does not exist on you SQL server…??

Hi Janis,

The link shows the code for 4.0 and it doesn’t work in Ax 2009.

Connection Problem: It says that user can not be logged on, OLEDB does not support or driver is not installed.

Abhishek

public boolean fetch()

{

boolean ret;

Connection Connection;

Statement Statement;

ResultSet ResultSet;

SqlStatementExecutePermission perm;

str sqlStatement = “exec RateVarianceReport”; // u can also use create here

;

Connection= new Connection();

Statement= Connection.createStatement();

perm = new SqlStatementExecutePermission(sqlStatement );

perm.assert();

ResultSet= Statement.executeQuery(sqlStatement );

while ( ResultSet.next() )

{

info(strfmt(“my SP result = %1”, ResultSet.getString(1)));

}

return ret;

}

Error:

Request for the permission of type ‘SqlStatementExecutePermission’ failed.

(S)\Classes\SqlStatementExecutePermission\demand

(S)\Classes\Statement\executeQuery

(C)\Reports\han_test\Methods\fetch - line 15

(C)\Classes\ReportRun\run

(C)\Classes\SysReportRun\run - line 26

(C)\Classes\RunBaseReport\run - line 34

(C)\Classes\SysReportRun\run - line 15

Anybody have solution, i called the store procedure with above code and give the error message by the system.

Hi Soni,

To execute a stored procedure from X++ use the Server method, the Client method does not have permissions. Following is the screen shot of the code from Server method. you don’t require any special privileges or permissions to execute a stored procedure. if used other then Server method, a message should appear like this ‘Request for the permission of type ‘SqlStatementExecutePermission’ failed.’