web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

odbc catch clause

(0) ShareShare
ReportReport
Posted on by

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 have the same question (0)
  • Suggested answer
    Jesus R. ABASCAL Profile Picture
    1,450 on at

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

               }

  • Community Member Profile Picture
    on at

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

    Thanks :)

  • Suggested answer
    Malcolm Burtt Profile Picture
    1,475 on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans