Solved

on error resume next

Posted on 2012-12-27
2
402 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 33

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

756 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