Hi all,
I want to catch a duplicate key exception. I do not want to provide that
verbose message from the MSSQL server - I would put a user friendly message
out, like
"The item you have added already exists in the database. Please change
the description and try to save again."
instead of
System.Data.Sql Client.SqlExcep tion: Cannot insert duplicate key row in
object 'Tree' with unique index 'KeySiteParentT reeNodename'.
The statement has been terminated.
at System.Data.Sql Client.SqlComma nd.ExecuteReade r(CommandBehavi or
cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery()
at ClaPub.DataAcce ss.ExecuteComma nd(String SQL, DataElements&
DataElements, BinaryDataEleme nts& BinaryDataEleme nts) in C:ClaPubClasses Data
Access ClassesDataAcce ss.vb:line 129
How do I do this? because the only error captured by .net is the general
System.Data.Sql Client.SqlExcep tion. I have tried using
System.Data.Dup licateNameExcep tion but that is not caught.
Try
SqlConnection.O pen()
m_ReturnValue = SqlCmdObj.Execu teNonQuery()
SqlConnection.C lose()
Catch e As System.Data.Sql Client.SqlExcep tion 'THIS IS CAUGHT
EVERY TIME
...
Catch e As System.Data.Dup licateNameExcep tion 'THIS IS NEVER
CAUGHT
...
Catch e As System.Data.NoN ullAllowedExcep tion 'THIS IS NEVER
CAUGHT
...
End Try