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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

What is exception error for failed sql query ?

(0) ShareShare
ReportReport
Posted on by

Hi guys,

When running my code that has a SQL query, such as this : 

select firstonly SalesId from custInvoiceJourLoc where custInvoiceJourLoc.InvoiceId == conPeek(TempInvoices,1)
join firstonly DefaultDimension
       from saleslineloc order by RecId
       where salesLineLoc.SalesId == custInvoiceJourLoc.SalesId;

Often I'm hit error and error comes with this message : 

pastedimage1679029598603v1.png

I know what is the error, but may I know what Exception error we can use for this ? Is there any special Exception error for failed Sql query ?

Thanks,

I have the same question (0)
  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    Hi VoltesDev,

    I guess its belongs to exception of type NullReferenceException.

    Thanks,

    Girish S.

  • Suggested answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    This is not a exception related to queries. It's object about object references in the application tier. It happens when you're trying (for example) to call a method on a reference that don't refer to any object at all.

    For instance:

    Args args; // The variable is empty.
    args.parm(); // We're trying to call parm() method of no object, which isn't possible to do.

    It's System.NullReferenceException, but you normally shouldn't try to catch it. Instead, you should prevent the exception from occuring by fixing the bug in code.

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi,I think this error will occur when container is null, so better to create  a variable for InvoiceId and map conPeek(TempInvoices,1) in that variable. move your select statement in If condition that it should run only if InvoiceId has a value.

  • VoltesDev Profile Picture
    on at

    Hi all,

    Yes, all the reason are correct. It is because the container is null. The plan is to catch it, and I will have an insert to ErrorLog procedure. Is there a reason why there is no exception for this ? instead we should fix the bug or make an IF condition to run when it is not null ?

    Thanks,

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    What do you mean by "why there is no exception for this"? Isn't the whole thread about this exception?

    But it's just the last resort; you shouldn't get into this situation. Also, you see that this generic exception tells you nothing about the actual cause, therefore it's difficult to debug. Even if you log it, it tells you nothing more than that you have a bug in code.

    Check if you have values to work with and if not, either skip the logic or throw an error explaining the problem.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans