Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catch SqlException

Status
Not open for further replies.
Jan 9, 2003
147
US
Hi,

Is there a better way to access the error codes in ASP.NET for a SqlException than:

Code:
Try
    'access data class which re-throws the sql error exception if it finds one

Catch sqlerror As SqlException
    Select Case sqlerror.Number
        Case 2627 'Sql error for key vilation
            'display error for key violation
        Case Else
            'display general SQL error
    End Select
Catch ex As Exception
    'display general error
End Try

It seems like there should be a more graceful way to get at the particular SQL error, like SqlError.isKeyViolation or something....

Thanks,
FD
 
I agree with you there. When I first started using .NET I felt the same way .. Why are there not more specific error messages. Seems like for now, you have to do it this way, unless someone else has found a way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top