Reputation: 15545
consider there is n-tier architecture in asp.net 3.5 application with c# language and Database in the sql server 2008.
Suppose we called the stored procedure exist in database, in our data access layer. But while execution of the stored procedure ,It gets exception. (which may facilitate to throw out in stored procedure) then how application know what is the exception exactly?
Is ADO.NET have capability to understand and represent the thrown exceptions by sql sql server. I know there is SQLException namespace provided by CLR's exception handling module. but as per my experience, this module can not represent the validation exceptions as it is encountered in sql server. Can somebody correct me and guide properly in handling the sql server exceptions form the dot net application ? and how we can handle them ? are we need to wait for execution/ reach at catch block always in dataaccess layer?
May be this question repeats, but I want to share my experience.
Upvotes: 0
Views: 620
Reputation: 7758
You should be validating and/or sanitising all the data that has been input before it reaches the database, so unless the DB is not present or there is a bug in a SP you shouldn't really get SQL exceptions.
From my experience you would catch the SQL Exception log it, wrap it in an ApplicationException and return a user friendly error to the UI.
Upvotes: 1