Bypassing a database connection

Discussion in 'ASP General' started by Andy Lee, Jun 24, 2004.

  1. Andy Lee

    Andy Lee Guest

    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
    Andy Lee, Jun 24, 2004
    #1
    1. Advertising

  2. Andy Lee

    Evertjan. Guest

    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)
    Evertjan., Jun 24, 2004
    #2
    1. Advertising

  3. Andy Lee

    Evertjan. Guest

    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)
    Evertjan., Jun 24, 2004
    #3
  4. Andy Lee

    Patrice Guest

    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." <> 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)
    Patrice, Jun 24, 2004
    #4
  5. Andy Lee

    Evertjan. Guest

    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)
    Evertjan., Jun 24, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MB
    Replies:
    3
    Views:
    8,695
    =?Utf-8?B?c3Jpbmk=?=
    May 13, 2004
  2. Russ

    bypassing a validation

    Russ, Jul 3, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    335
    M. Zeeshan Mustafa
    Jul 3, 2004
  3. David Hearn
    Replies:
    2
    Views:
    423
    David Hearn
    Jul 16, 2004
  4. tim almond

    Question regarding bypassing security

    tim almond, Apr 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    314
    Robbe Morris [C# MVP]
    Apr 11, 2005
  5. Replies:
    4
    Views:
    341
Loading...

Share This Page