Solved

on error resume next

Posted on 2012-12-27
2
408 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
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.

752 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