Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

odbc catch clause

Posted on by Microsoft Employee

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

  • Suggested answer
    Malcolm Burtt Profile Picture
    Malcolm Burtt 1,475 on at
    RE: odbc catch clause

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: odbc catch clause

    When there is a mistake on the sql I cannot catch it even on Exception::CLRError, as your suggestion.

    Thanks :)

  • Suggested answer
    Jesus R. ABASCAL Profile Picture
    Jesus R. ABASCAL 1,450 on at
    RE: odbc catch clause

    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();

               }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans