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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to trap Oracle error in ASP

Status
Not open for further replies.

MavrickStl

Programmer
Feb 20, 2001
71
US
How can I trap this error (and show it in simple words to the user) returned by oracle while calling a trigger via an asp page:

Microsoft OLE DB Provider for Oracle error '80040e2f'

ORA-00001: unique constraint (BRAG.SYS_C001009) violated ORA-06512: at "Nix.NEW_USER_LOGIN", line 25 ORA-04088: error during execution of trigger 'Nix.NEW_USER_LOGIN' ORA-06512: at "Nix.EMP_ADD", line 14 ORA-06512: at line 1

Here is my ASP code:

With objCommand
.CommandText = "{Call emp_add(?,?,?,?,?,?)}"
.CommandType = adCmdText
.Parameters(0).Value = varNixUserId
.Parameters(1).Value = varFirstName
.Parameters(2).Value = varLastName
.Parameters(3).Value = varEmail
.Parameters(4).Value = varLeadId
.Parameters(5).Value = varPassword
.Execute()
------------------------

Thanks,
Mav
 
on error resume next 'turn off error trapping
With objCommand
.CommandText = "{Call emp_add(?,?,?,?,?,?)}"
.CommandType = adCmdText
.Parameters(0).Value = varNixUserId
.Parameters(1).Value = varFirstName
.Parameters(2).Value = varLastName
.Parameters(3).Value = varEmail
.Parameters(4).Value = varLeadId
.Parameters(5).Value = varPassword
.Execute()
if err.number <> 0 then 'was there an error?
call errorTrap(err.number) 'call your own function
end if
on error goto 0 'turn trapping back on

'-----------------------------
sub errorTrap(num)
if num = &quot;80040e2f&quot; then
response.write(&quot;There has been a primary key conflict&quot;)
response.flush
response.end
elseif num = &quot;otherErrorNumber&quot; 'you get the idea here
response.write(&quot;blahblahblah&quot;)
else 'catch other exceptions
response.write(&quot;There has been an unknown error&quot;)
response.flush
response.end
end if
end sub

and so on -- actually, if this is something that you will want to do often, I would spend the time to track down and specify all known errors and write a be-all-end-all error trapping function and stick it in an include file so you can use it on all your pages, and use your own custom error trapping so your users get readable error messages instead of the default ones.

hope that helps! :)
Paul Prewett
penny.gif
penny.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top