Solved

on error resume next

Posted on 2012-12-27
2
394 Views
Last Modified: 2012-12-28
I put in this code to catch a 500  error. I want the page to continue running and not move the user to a different page.
with the code, if the connection works fine, the page loads and the information is inserted into the database.
If the connection doesn't work, the page keeps running in a circle and causes a timeout.
What did I put wrong?
<% 
 connectionComplete = "false"
On Error Resume Next
 If err.Number = 0 Then

 if myConn.State = 1 then

  On Error Goto 0

Set press_cmd = Server.CreateObject ("ADODB.Command")
press_cmd.ActiveConnection = myConn
press_cmd.CommandText = "SELECT    * FROM         dbo.k4kPressRelease  ORDER BY date DESC"
press_cmd.Prepared = true
On Error Resume Next
If err.Number = 0 Then

Set press = press_cmd.Execute
connectionComplete = "true"

press_numRows = 0
end if
end if 
else
connectionComplete = "false"
 ' Error trapping - connection failed
end if


%>

Open in new window

0
Comment
Question by:rivkamak
2 Comments
 

Expert Comment

by:gopakumarvr
ID: 38726109
I doubt your "if 'myConn.State' = 1 then" fails and the error, makes run the Goto command to line 0 again and again!!
            On Error Goto 0
0
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
ID: 38727060
you need to put the err.number check right after the line(s) you expect to fail. i would put the "On Error Resume Next" at the top of the page and then check for errors as you go down the page. try this:

<% 
 connectionComplete = "false"

On Error Resume Next

Set press_cmd = Server.CreateObject ("ADODB.Command")
press_cmd.ActiveConnection = myConn
press_cmd.CommandText = "SELECT    * FROM         dbo.k4kPressRelease  ORDER BY date DESC"
press_cmd.Prepared = true

'-- do a check right after the execute command as thats where a potential error can occur
Set press = press_cmd.Execute
if err.Number = 0 then
    connectionComplete = "true"
else
    connectionComplete = "false"
end if

'-- if you dont want to do error handling on the rest of the page, then you could turn it off here
on error goto 0
%>

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now