I wrote a job with following code with following code:
DictTable dictTable = new DictTable(tableNum(custTable));
Connection connection = new Connection();
Statement statement = connection.createStatement();
str sql= “select * from CustTable”;
rs = statement.executeQuery(sql);
while (rs.next() )
Statement : rs=statement.executeQuery(sql)-gives me an error:
Request for the permission of type ‘SqlStatementExecutePermission’ failed.
(C) \Jobs\CSA_AutoPadTest - line 20
I can not find class: SqlStatementExecutePermission.
I am connected as admin. How can i grant permission for this type of actions?
Perhaps you might want to check the authentication method on the database. Please make sure that you are using the right user credentials from the code.
The class that you mentioned is available under system documentation → classes in AOT.
Hope this helps,
If you haven’t managed to fix the problem yet, please do a search for SQLStatementExecutePermission in the Ax 4.0 developer’s guide. There are some code snippets there which you might want to give a try.
What Dev guide are you reffering to? the online one on MSDN?
Or is there a dev guide other than that?
I tried to use the code provided here
but still unable to figure it out.
Actually, my task is a little harder. I have a separate SQL database on the same SQL server that I need to get data from.
Is there a good example how this can be achieved?
Actually, I got it working a split second after I wrote the post
But still, what I do now is specify the database i want to connect to, the user that owns the table and the table name, like this:
select * from AXDBtest.dbo.sTestTable
using the Connection Class, not the ODBCconnection.
Any better suggestions? (it’s my first hour working with the new DAX 4.0, hurray)[<:o)]
try like this
Result set rt;
sql = " select * from custtable";
connection = new userconnection();
st = connection.createstatement();
rt = st.executequery(sql);
If you are looking to use different DataBase than the Axapta’s one, this is different story.
What Microsoft Provides in their MSDN is how to connect to the AOT database.
any how I check the code and it work pretty fine with me.
creating new class and I put the code as main method.
server static void main(Args args)
Connection con = new Connection();
Statement stmt = con.createStatement();
sql = strfmt('
hope this can help you
connection con = new connection();
command= “sql script here”;
_perm = new SqlStatementExecutePermission(command);
sta = con.createStatement();
I found it. [:D]
there are two conditions you have to make sure of them so the code will work.
by the way all what the guys repied is correct code, but.
you have to:
1- create new class and but that code in the main method"
*static void main(Args args)*
2- make sure that the property of the class “RunOn” is set to "server: this step is too IMPORTANT since the connection can only happen on the SERVER and it will fail if you run it in client.
I hope this is the way.
please try it and feed us back.