I am using odbc to retrieve data.
Code looks like :
OdbcConnection odbcConnection; str sql; int res; ... Statement statement; try { sql = 'bla bla'; new SqlStatementExecutePermission(sql).assert(); //Prepare the sql statement. statement = odbcConnection.createStatement(); res = statement.executeUpdate(sql); } catch { info(CLRInterop::getLastException()); res = -1; } ...
I have wrong sql, but AX through an exception, without reaching the catch clause.
How can I catch wrong sql in odbc?
Thanks :)
*This post is locked for comments
I'm not sure which exception you would need to catch for this but the error information can be retrieved using the statement.getLastError() and statement.getLastErrorText() methods.
When there is a mistake on the sql I cannot catch it even on Exception::CLRError, as your suggestion.
Thanks :)
Try this catch code:
catch(Exception::CLRError)
{
CodeAccessPermission::revertAssert();
perm = new InteropPermission(InteropKind::ClrInterop);
if (perm == null)
return;
perm.assert();
e = ClrInterop::getLastException();
msgError = e.get_Message();
CodeAccessPermission::revertAssert();
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,219 Super User 2024 Season 2
Martin Dráb 230,056 Most Valuable Professional
nmaenpaa 101,156