Hello - In a multi-tier SOA architecture, what kind of strategy do you use to handle database exceptions?
Do you include a property on your MessageContract response to pass some type of database exception information back to the user - maybe some type of error code the user can report back to the helpdesk?
Or do you catch the database exception at the middle tier, log it and then somehow report a generic FaultException back to the user - like maybe a custom DatabaseFaultException?
I think it depends on how much information you'd like to provide (about the exceptions occured at datatbase side) to the front-end callers.
For simple case that you do not want too much encapsulation, you can just capture the database side exception and rethrow it with a new one (set the original one as inner exception) and let the runtime handle it. This will provide the raw exception information
to the up-stream callers.
You can also define your custom exceptions and always throw the custom exceptions to the front callers only. For example, you use a big try...catch... block to wrap the entire data accessing code block. Whenever exceptions occur(catched in your code block),
you create a new custom exception and only include the necessary information about the database side error( such as the target database, table, query info, invoked method ...). Thus the front-end callers will only receive the encapsulated error information.
Well - you should never provide database details to client-side callers. That would be a security hole because the exception details could possibly contain info about database, table and column names, stored procedure names, etc. I think throwing a FaultException<Database>
would be too specific because the client should not be expected to catch exceptions at that level of detail. Has anyone here tried creating and using a custom FaultException<System>? This could have a Type property to indicate the type of system exception
that occurred like Database. However, can you think of any system-level errors that might happen in a WCF service other than a database error where WCF could still throw the exception? For example, if the server on which the WCF service resides went down
then the WCF service would not be able to throw a ServerDown exception. What are your thoughts on this?
dotnetterAMG...
Member
234 Points
510 Posts
how to handle database exceptions in wcf soa?
Nov 04, 2012 06:08 PM|LINK
Hello - In a multi-tier SOA architecture, what kind of strategy do you use to handle database exceptions?
Do you include a property on your MessageContract response to pass some type of database exception information back to the user - maybe some type of error code the user can report back to the helpdesk?
Or do you catch the database exception at the middle tier, log it and then somehow report a generic FaultException back to the user - like maybe a custom DatabaseFaultException?
Steven Cheng...
Contributor
4199 Points
548 Posts
Microsoft
Moderator
Re: how to handle database exceptions in wcf soa?
Nov 05, 2012 01:24 AM|LINK
Hi dotnetterAMG123,
I think it depends on how much information you'd like to provide (about the exceptions occured at datatbase side) to the front-end callers.
For simple case that you do not want too much encapsulation, you can just capture the database side exception and rethrow it with a new one (set the original one as inner exception) and let the runtime handle it. This will provide the raw exception information to the up-stream callers.
You can also define your custom exceptions and always throw the custom exceptions to the front callers only. For example, you use a big try...catch... block to wrap the entire data accessing code block. Whenever exceptions occur(catched in your code block), you create a new custom exception and only include the necessary information about the database side error( such as the target database, table, query info, invoked method ...). Thus the front-end callers will only receive the encapsulated error information.
Feedback to us
Microsoft One Code Framework
dotnetterAMG...
Member
234 Points
510 Posts
Re: how to handle database exceptions in wcf soa?
Nov 05, 2012 02:14 AM|LINK
sandy060583
Star
8714 Points
1624 Posts
Re: how to handle database exceptions in wcf soa?
Nov 05, 2012 06:45 AM|LINK
Hi dotnetter,
Here is the link which explain some of the best practice to handle the fault in wcf.
Hope it will help to solve your problem !!!
Ramani Sandeep (My Blog)
(MCTS, MCC-2011)
ToughMan
Participant
1490 Points
635 Posts
Re: how to handle database exceptions in wcf soa?
Nov 11, 2012 03:02 AM|LINK
Don't manage the whole exceptions in ur WCF, but use try……catch where you refer your WCF