Bypassing a database connection

A

Andy Lee

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
 
E

Evertjan.

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
%>
 
E

Evertjan.

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:


<%
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 ?
 
P

Patrice

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

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top