More friendlier OleDb error message.

Instead of the error message

"The statement has been terminated. Violation of PRIMARY KEY....."

Is there anyway to trap different types of error (...primary key, length too long, unique constraint) and provide a nicer error message to the user.

How do you guys do it ? can share ?
fkmfkmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PockyMasterCommented:
Most of the time, these kind of things happen when you want to perform some kind of sequence of actions. E.g. a user tried to store a product he just designed.
Does he want to know a primary key was violated?
No, he wants to know just if his product was stored or not.
Your application might write the real message to a log or something like that. So in case your angry customer calls you, you have a way to sort it out :D

0
Bob LearnedCommented:
Try

Catch ex As OleDbException

  Throw New Exception("This is a better exception message")

End Try

Bob
0
fkmfkmAuthor Commented:
Thanks Pocky and LearnedOne,

I guess the answer is the combination of both your suggestions.

TheLearnedOne,

Is there anyway to catch more specific error eg. Primary Key violation, Secondary ..etc ?

0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Bob LearnedCommented:
While this is not a comprehensive list, these are the data exception that I have found so far:

System.Data      ConstraintException
System.Data      DataException
System.Data      DBConcurrencyException
System.Data      DeletedRowInaccessibleException
System.Data      DuplicateNameException
System.Data      InRowChangingEventException
System.Data      InvalidConstraintException
System.Data      InvalidExpressionException
System.Data      MissingPrimaryKeyException
System.Data      NoNullAlllowedException
System.Data      ReadOnlyException
System.Data      RowNotInTableException
System.Data      StringTypingException
System.Data      TypedDataSetGeneratorException
System.Data      VersionNotFoundException
System.Data.OleDb      OleDbException

Bob
0
fkmfkmAuthor Commented:
Thanks TheLearnedOne,

A step closer now..

Ok with SQL I always have this problem. When my data exceeds the lenght of the field..I will get some error message .. The problem is I do not know which field is this that is exceeded.

So to make my problem more general..is there away (easy though) to highlight to there user some thing more specific like.."Data Address is too long" etc...Something so that the user knows how to rectify the problem himself.



Thank you.
0
Bob LearnedCommented:
If you are wanting that information, you are going to have write some code to check for string columns, string lengths, and compare them against the defined size for the corresponding column in the table.

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.