fkmfkm
asked on
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 ?
"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 ?
Try
Catch ex As OleDbException
Throw New Exception("This is a better exception message")
End Try
Bob
Catch ex As OleDbException
Throw New Exception("This is a better exception message")
End Try
Bob
ASKER
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 ?
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 ?
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 DeletedRowInaccessibleExce ption
System.Data DuplicateNameException
System.Data InRowChangingEventExceptio n
System.Data InvalidConstraintException
System.Data InvalidExpressionException
System.Data MissingPrimaryKeyException
System.Data NoNullAlllowedException
System.Data ReadOnlyException
System.Data RowNotInTableException
System.Data StringTypingException
System.Data TypedDataSetGeneratorExcep tion
System.Data VersionNotFoundException
System.Data.OleDb OleDbException
Bob
System.Data ConstraintException
System.Data DataException
System.Data DBConcurrencyException
System.Data DeletedRowInaccessibleExce
System.Data DuplicateNameException
System.Data InRowChangingEventExceptio
System.Data InvalidConstraintException
System.Data InvalidExpressionException
System.Data MissingPrimaryKeyException
System.Data NoNullAlllowedException
System.Data ReadOnlyException
System.Data RowNotInTableException
System.Data StringTypingException
System.Data TypedDataSetGeneratorExcep
System.Data VersionNotFoundException
System.Data.OleDb OleDbException
Bob
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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