Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

on error resume next

Posted on 2012-12-27
2
Medium Priority
?
417 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 34

Accepted Solution

by:
Big Monty earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

877 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