Solved

on error resume next

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

622 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