[2005] Error Trapping Help Please
Hello,
I am stumbling my way through VB.Net, but one area I struggle with is Error Trapping.
Basically I am getting the following error when I try to insert an entry into my table on the DB.
Code:
System.Web.Services.Protocols.SoapException:
Server was unable to process request. --->
System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint
'PK_tbl_Holidays'. Cannot insert duplicate key in object 'tbl_Holidays'.
The statement has been terminated.
blah
blah
blah.....
Now I know why I am getting this error obviously, but I'd like to display a friendly message to the user to advise them, rather than them getting a large soap error message like this.
How can I do this ?
And are there any resources you'd recommend to deal with error trapping ?
Re: [2005] Error Trapping Help Please
vb.net Code:
Try
'Add code which could produce error here
Catch ex As Exception
'Add error handling code
End Try
Within the error handling code you can find out the error message by using ex.Message()
Re: [2005] Error Trapping Help Please
Thanks computafreak, but I already have it in a try...catch, but that doesn't really help.
All that happens is the huge message above is displayed on the screen, whereas I want a much smaller message along the lines of "Cannot create a duplicate record in the Holidays Table" or something like that.
Re: [2005] Error Trapping Help Please
Take a look at this thread:
http://www.vbforums.com/showthread.php?t=485003
We had a discusion of error traping there and it include issues about constraints.