Hi

I have a bit of code which executes an SQL statement.on my webpage. If the
execution fails i do not want a standard error coming up that asp normally
shows - instead i would like something like

if (cnn.execute) = failed Then
'Do This
End If

Re: Bypassing a database connection by Evertjan

Evertjan
Thu Jun 24 04:12:47 CDT 2004

Andy Lee wrote on 24 jun 2004 in
microsoft.public.inetserver.asp.general:

> I have a bit of code which executes an SQL statement.on my webpage.
> If the execution fails i do not want a standard error coming up that
> asp normally shows - instead i would like something like
>
> if (cnn.execute) = failed Then
> 'Do This
> End If
>

<%
on error resume next
set CONNECT = server.CreateObject("ADODB.Connection")
CONNECT.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" &_
Server.MapPath("notexisting.mdb") & ";"

if err.number <> 0 then
response.write "Database NOT found"
else
response.write "Database found"
end if
on error goto 0
%>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: Bypassing a database connection by Evertjan

Evertjan
Thu Jun 24 04:16:34 CDT 2004

Evertjan. wrote on 24 jun 2004 in
microsoft.public.inetserver.asp.general:

> Andy Lee wrote on 24 jun 2004 in
> microsoft.public.inetserver.asp.general:
>
>> I have a bit of code which executes an SQL statement.on my webpage.
>> If the execution fails i do not want a standard error coming up that
>> asp normally shows - instead i would like something like
>>
>> if (cnn.execute) = failed Then
>> 'Do This
>> End If
>>
>
> <%
> on error resume next
> set CONNECT = server.CreateObject("ADODB.Connection")
> CONNECT.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" &_
> Server.MapPath("notexisting.mdb") & ";"
>
> if err.number <> 0 then
> response.write "Database NOT found"
> else
> response.write "Database found"
> end if
> on error goto 0
> %>
>

I now see you want to forgo a sql fault, [which is clearly your own
mistake]

Just try the same error trapping ?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: Bypassing a database connection by Patrice

Patrice
Thu Jun 24 07:33:37 CDT 2004

My personal preference would be rather to create a custom error page :
http://support.microsoft.com/default.aspx?scid=kb;EN-US;224070

You could send a mail with error details and behave differently on your
development server.

IMO the key advantage is that you won't trap the same way things you are not
prepared for (for example the code below will show always a "database not
found" even if the problem is somewhere else in the connection string).

To trap for this specific error I would just test the file existance (using
Scripting.FileSystemObject) though this is IMO useless if you can't do
anything about it.

In short I would say :
- have a "catch all" page that display a generic message and mail details
- if you can do something when a particular condition is encoutered, handle
this at the code level (preferably byt testing before the error arise ie.
testing the file existance rather than trapping an error becuase the file is
not found etc...)

Patrice

--

"Evertjan." <exjxw.hannivoort@interxnl.net> a écrit dans le message de
news:Xns95127222D18E5eejj99@194.109.133.29...
> Andy Lee wrote on 24 jun 2004 in
> microsoft.public.inetserver.asp.general:
>
> > I have a bit of code which executes an SQL statement.on my webpage.
> > If the execution fails i do not want a standard error coming up that
> > asp normally shows - instead i would like something like
> >
> > if (cnn.execute) = failed Then
> > 'Do This
> > End If
> >
>
> <%
> on error resume next
> set CONNECT = server.CreateObject("ADODB.Connection")
> CONNECT.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" &_
> Server.MapPath("notexisting.mdb") & ";"
>
> if err.number <> 0 then
> response.write "Database NOT found"
> else
> response.write "Database found"
> end if
> on error goto 0
> %>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)



Re: Bypassing a database connection by Evertjan

Evertjan
Thu Jun 24 17:34:13 CDT 2004

Patrice wrote on 24 jun 2004 in microsoft.public.inetserver.asp.general:
> My personal preference would be rather to create a custom error page :
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;224070

[please do not toppost on usenet]

This is not possible for the many of us that rent a virtual server.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)