Contents

Execute Stored Procedure from X++ code

Contents

To execute a stored procedure from X++ use the Server method, the Client method does not have permissions; you don’t require any special privileges or permissions to execute a stored procedure. If we use other than Server method, a message should appear like this

Warning
Request for the permission of type SqlStatementExecutePermission failed.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public static void main(AssemblyLoadEventArgs _args)
{
    Connection con = new Connection();
    Statement stmt = new Con.createStatement();
 
    ResultSet r;
    str sql;
 
    SqlStatementExecutePermission perm;
    sql = stmt('EXEC [StoreprocedureName]');
    perm = new SqlStatementExecutePermission(sql);
    perm.assert();
    try
    {
        stmt.executeUpdate(sql);
    }
    catch (Exception::Error)
    {
        print "An error occured in the query";
        pause;
    }   
    CodeAccessPermission::revertAssert();
}