?
Solved

More friendlier OleDb error message.

Posted on 2006-03-26
6
Medium Priority
?
226 Views
Last Modified: 2011-10-03
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 ?
0
Comment
Question by:fkmfkm
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:PockyMaster
ID: 16293052
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16300603
Try

Catch ex As OleDbException

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

End Try

Bob
0
 

Author Comment

by:fkmfkm
ID: 16316968
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
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 16320692
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
 

Author Comment

by:fkmfkm
ID: 16350433
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 375 total points
ID: 16354367
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question