J
James Cooke
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.SqlClient.SqlException: Cannot insert duplicate key row in
object 'Tree' with unique index 'KeySiteParentTreeNodename'.
The statement has been terminated.
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at ClaPub.DataAccess.ExecuteCommand(String SQL, DataElements&
DataElements, BinaryDataElements& BinaryDataElements) in C:ClaPubClassesData
Access ClassesDataAccess.vb:line 129
How do I do this? because the only error captured by .net is the general
System.Data.SqlClient.SqlException. I have tried using
System.Data.DuplicateNameException but that is not caught.
Try
SqlConnection.Open()
m_ReturnValue = SqlCmdObj.ExecuteNonQuery()
SqlConnection.Close()
Catch e As System.Data.SqlClient.SqlException 'THIS IS CAUGHT
EVERY TIME
...
Catch e As System.Data.DuplicateNameException 'THIS IS NEVER
CAUGHT
...
Catch e As System.Data.NoNullAllowedException 'THIS IS NEVER
CAUGHT
...
End Try
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.SqlClient.SqlException: Cannot insert duplicate key row in
object 'Tree' with unique index 'KeySiteParentTreeNodename'.
The statement has been terminated.
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at ClaPub.DataAccess.ExecuteCommand(String SQL, DataElements&
DataElements, BinaryDataElements& BinaryDataElements) in C:ClaPubClassesData
Access ClassesDataAccess.vb:line 129
How do I do this? because the only error captured by .net is the general
System.Data.SqlClient.SqlException. I have tried using
System.Data.DuplicateNameException but that is not caught.
Try
SqlConnection.Open()
m_ReturnValue = SqlCmdObj.ExecuteNonQuery()
SqlConnection.Close()
Catch e As System.Data.SqlClient.SqlException 'THIS IS CAUGHT
EVERY TIME
...
Catch e As System.Data.DuplicateNameException 'THIS IS NEVER
CAUGHT
...
Catch e As System.Data.NoNullAllowedException 'THIS IS NEVER
CAUGHT
...
End Try