Skip to main content

Notifications

Announcements

No record found.

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,

  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: What is exception error for failed sql query ?

    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.

  • VoltesDev Profile Picture
    VoltesDev on at
    RE: What is exception error for failed sql query ?

    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,

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: What is exception error for failed sql query ?

    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.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: What is exception error for failed sql query ?

    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
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: What is exception error for failed sql query ?

    Hi VoltesDev,

    I guess its belongs to exception of type NullReferenceException.

    Thanks,

    Girish S.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans