Trapping odbc error when exec"ing INSERT command

Trapping odbc error when exec"ing INSERT command

am 22.03.2005 06:39:16 von Doug B

I hope this is the right group for this question, if it's not please
direct me.

I have a data-driven website that allows users to enter records for
sales leads. It all works perfectly. The only thing I want to do
right now is prohibit users from entering the same lead twice. I have
a PK field in the MS Access database that, obviously, disallows
duplicate records. However, when such an attempt is made, the browser
redirects to some generic ODBC error page with some cryptic numbers
and other information that will stymie the users. "It doesn't work",
they will say. The text of that error indicates that they tried to
add a record that violates the PK rule of disallowing duplicate
records. But they probably won't read it and it's truly ugly anyway.

How can I redirect to a custom error page or trap the error before the
ODBC error page is displayed and just display a msgbox or something
telling the user they attempted to add a record that already exists?

Thank you

Re: Trapping odbc error when exec"ing INSERT command

am 22.03.2005 10:06:01 von exjxw.hannivoort

Doo-Dah Man wrote on 22 mrt 2005 in microsoft.public.inetserver.asp.db:

> I hope this is the right group for this question, if it's not please
> direct me.
>
> I have a data-driven website that allows users to enter records for
> sales leads. It all works perfectly. The only thing I want to do
> right now is prohibit users from entering the same lead twice. I have
> a PK field in the MS Access database that, obviously, disallows
> duplicate records. However, when such an attempt is made, the browser
> redirects to some generic ODBC error page with some cryptic numbers
> and other information that will stymie the users. "It doesn't work",
> they will say. The text of that error indicates that they tried to
> add a record that violates the PK rule of disallowing duplicate
> records. But they probably won't read it and it's truly ugly anyway.
>
> How can I redirect to a custom error page or trap the error before the
> ODBC error page is displayed and just display a msgbox or something
> telling the user they attempted to add a record that already exists?
>

Something like this???

sql="UPDATE myTable SET .............."

on error resume next
session('theError')="" ' to be supersafe
conn.Execute sql
if err<>0 then
session('theError')=err
response.redirect "myErrorpage.asp"
end if


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)