what is the best practice for issuing an error from ssrs?

db042190 1,416 Reputation points
2021-11-08T18:21:26.527+00:00

hi we are currently on 2014 enterprise and will be on 2019 enterprise in the coming months.

on at least 24 of our reports, there is a set of parameters called minimum balance and maximum balance. I can get into a long explanation about negatives meaning the customer owes us and positives meaning we owe him, but the bottom line for this question is that by definition zero is invalid for a min or max balance.

i suspect that is difficult if not impossible to control from ssrs. who knows. maybe there is a way to introduce an ssrs expression based function before the proc is run?

so we are thinking about either throwing an exception in the proc or returning one liners to our tablix's with the appropriate error. exceptions sound like the more appropriate way to go but then we wonder about the whole "enabling remote errors" thing being a prerequisite to the user understanding what he sees once we throw the exception.

can someone guide us on best practice? we dont enable remote errors right now and i dont think we will be doing that.

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,102 questions
No comments
{count} votes

6 answers

Sort by: Most helpful
  1. ZoeHui-MSFT 18,746 Reputation points Microsoft Employee
    2021-11-09T07:36:00.28+00:00

    Hi @db042190 ,

    Do you mean that when the parameter of minimum balance and maximum balance reach a certain value , the report would like to generate a message saying something like "Error Message" ?

    If yes, I think custom code will be meet your requirement.

    Here is a same sample you may take a reference: http://experiencingmsbi.blogspot.com/2011/09/ssrs-calendar-and-date-restriction.html

    If I misunderstand your need, please incorrect me.

    Regards,

    Zoe


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    No comments

  2. db042190 1,416 Reputation points
    2021-11-09T12:58:20.977+00:00

    thx zoehui. yes, if either the min param value entered is zero or the max is zero we want to generate an eye catching error and block generation of a dataset. i'm going to read your article now.

    No comments

  3. db042190 1,416 Reputation points
    2021-11-09T13:22:46.34+00:00

    that is definitely an option but i was hoping to invoke such a function before the proc is run and stop the report rendering cold or throw an exception from the proc without affecting existing or adding new textboxes.

    is there a way for a raised error message to show "as is"? ie in the same area and in that familiar small font that general but ambiguous errors like insufficient permissions or dataset errors show? see below what i'm talking about where i removed a proc...

    147759-sampleexceptionwhenprocremoved.png

    No comments

  4. db042190 1,416 Reputation points
    2021-11-09T13:45:50.643+00:00

    i added the code you see below to the proc and get the same ambiguous error shown in the last post...

    if (@pMinBalance=0 or @pMaxBalance =0) raiserror (N'Zero is invalid as a balance range boundary',10,1)
    
    No comments

  5. ZoeHui-MSFT 18,746 Reputation points Microsoft Employee
    2021-11-10T07:39:50.913+00:00

    Hi @db042190 ,

    Thanks for your detailed response, check below to see if it could bring you some ideas.

    In my case, when the bookid<3, it will thrown 'paramter.value is invalid as a balance range boundary'

    In the report add a textbox with expression =IIF(Count(Fields!BookID.Value, "DataSet1")=0,Parameters!bookid.Value+" is invalid as a balance range boundary", nothing)

    In the dataset I use below code, you may change it with your data.

    if @bookid>'3'  
    SELECT [BookID]  
          ,[Book Title]  
          ,[Book Price]  
      FROM [AdventureWorksDW2012].[dbo].[books]  
    where bookid in(@bookid)  
    else  
    select null  
    

    And then check my report as shown.

    148121-untitled1.png

    Regards,

    Zoe


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    No comments