Results 1 to 4 of 4

Thread: [2005] Error Trapping Help Please

  1. #1

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    [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 ?
    Last edited by Jonny1409; Aug 23rd, 2007 at 06:53 AM.

  2. #2
    Lively Member
    Join Date
    Oct 2006
    Posts
    88

    Re: [2005] Error Trapping Help Please

    vb.net Code:
    1. Try
    2.     'Add code which could produce error here
    3. Catch ex As Exception
    4.     'Add error handling code
    5. End Try
    Within the error handling code you can find out the error message by using ex.Message()

  3. #3

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    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.

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width