Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:55:47+00:00 2026-05-29T09:55:47+00:00

Should application expect the unexpected when fetching data from database? Lets say that we

  • 0

Should application expect the unexpected when fetching data from database? Lets say that we have stored an enumeration value in a column (int or text). When we return values from database, we cast the value to enumeration type. What if someone has altered data in database manually, and broke data integrity, so our cast is failing?

Another example would be when a data type in c# is of less range that equivalent field in database. If anyone puts value in this value manually, lets say to database max value, then application would throw out of range exception.

Should we and how handle this exceptions?

Edit: Since most of the answers are similar, I am going to rephrase the question. It is implied that there is exception logging in the application. The problem is: when user queries for some data, and the data is corrupted (not from application CRUD operations, but outside), data conversion from database to model will fail, and user will get no data at all. Is it acceptable to have such a state in application, since the application itself didnt cause it?

Validating data would create a big slowdown on data fetching. Imagine that you need to check each decimal value if its out of range?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:55:48+00:00Added an answer on May 29, 2026 at 9:55 am

    I always took it to be standard practice to place any database interaction code in the datalayer with in try...catch blocks so that you can handle situations such as this in a civilised manner.

    I don’t check for every eventuality, but being able to log exceptions will prove useful when supporting your code in the long run.

    In the case of a live system it’s always good to have such information especially when you can accuse a customer of fiddling with things that they shouldn’t have.

    edit

    As I said you can’t check for every eventuality, but you can trap exceptions caused by situations such as casting a value to an enum that doesn’t exist.

    It isn’t really possible to check for values that are out of range, other than the extreme e.g. a field unexpectedly comes back as DBNull or fails convertion from database datatype to model data type. In such a case handling the error and presenting the user with an error message or "VALUE UNKNOWN" type indicator should be okay.

    The problem here is that you have a user who is changing data without using your application.

    You may already be implementing IDataErrorInfo in your data model, specifically to validate user input, if not look here for an example, or maybe something similar.

    But you can’t really cope with ‘corrupted’ data being a valid value i.e. if your enum field was changed to one that was correct value wise but incorrect logically you wouldn’t know until you came to use it that it was wrong.

    A pragmatic approach has to be taken as you rightly said validation of thousands or even just hundreds of values being retrieved from the database would have an unexceptable hit on performance.

    But saying "There’s been an error, please contact your system administrator" or something similar is perfectly acceptable in my view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Tapestry application, that retrieves data from a form, writes it to
I have created an SMS application in .NET. I wanted that the application should
I'm trying to start unit testing on my application (should have done so from
I have a core data application that uses an NSPredicate in one of its
I have exceptions created for every condition that my application does not expect. UserNameNotValidException
I have written an application in C# that receives UDP packets continuously streamed from
I know that the reminder application should display a badge or sound or kind
I know that a command line application should return 0 on success. But are
Consider an iPhone application that is a catalogue of animals. The application should allow
What type of performance should I expect out of web services? I have an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.