0

I have a problem where i want to show specific Exception Errors inside my reports(making life easier for the guy who has to fix things if they are borken).

I want my SQLexception

Not allowed to embed images(SQL) enter image description here

and my SSRS exception

Not allowed to embed images(SSRS) enter image description here

to both show the SQL exception message.

Does anybody have a clue how i can fix this?

so far I have only hit a wall

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Bernard Walters
  • 391
  • 1
  • 4
  • 16
  • I think u want to use the SQLException Number Property as shown here http://stackoverflow.com/questions/6221951/sqlexception-catch-and-handling – Fuzzybear Nov 28 '16 at 13:11

1 Answers1

1

First, you need to wrap the SQL in a try ... catch block (see here). This gives you control over what happens when the SQL throws an error and allows you to see the Error Message (see here).

In order for you to be able to display the error in SSRS, you have to still return a SELECT statement with the same columns you would have normally. This is because SSRS needs to know the column names ahead of time. So add a column to your original dataset like so:

SELECT Col1, Col2, ... , NULL as ERROR_MESSAGE

And then add this in your catch block:

SELECT NULL AS Col1, NULL as Col2, ... , ERROR_MESSAGE() as ERROR_MESSAGE

Then, in the report, you can check the Max(Fields!.ERROR_MESSAGE.Value) to determine if you should display the error message in that column or regular data.

StevenWhite
  • 5,907
  • 3
  • 21
  • 46