on error resume next

Hello All;

This is my situation.
I do not have access to the 500-100 pages (Please don'y ask, it is beyond me)

OK.
I have been reading: http://www.powerasp.com/content/new/on-error-resume-next.asp
But this is opening the database and presenting an error and doing something.
I need to do it before this.

My issue is this:

I want to trap when the SQL Server goes down (Due to Reboot or Environmental OFF-LINE)
Instead of showing this error: (Or any error that deals with SQL Server itself not being there)

SQL Server does not exist or access denied.

And show the visitor something like:

if err then
Sorry, there seems to be a problem, please wait while we refresh the page in 5 seconds.
else
load the database.

How can this be accomplished?

---
Also, can I use the <%on error resume next%> to NOT display any asp errors to the page?
Is there a way to do it? Since I cannot do no 500-100 page which really sucks.
I need to find a way NOT to let the user see anything like this.

(Yes I know, this is a pain, and hopefully by Christmas 2011, I will be hosting in-house with my company, but right now, this is as good as it gets for me...)

Take Care
Carrzkiss
LVL 31
Wayne BarronAuthor, Web DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony PerkinsCommented:
>>Also, can I use the <%on error resume next%> to NOT display any asp errors to the page?<<
Sure.  This is in fact the only way you can trap errors with ASP.  Just try and make the code sections that use this to be very small.  In other words say you want to check whether SQL Server is online then your code should look something like this:

Dim ErrNumber

Set  cn = Server.CreateObject("ADODB.Connection")

cn.ConnectionString = "YourConnectionStringGoesHere"
On Error Resume Next
cn.Open
Set ErrNumber = Err.Number
On Error GoTo 0
If ErrNumber > 0 Then
     ' You Error Handling Code goes here
Else
    ' Rest of your code goes here
End
Wayne BarronAuthor, Web DeveloperAuthor Commented:
You state:  >> use this to be very small

What exactly would apply as: SMALL?

Once the connection is opened, when (or) where would I add in the END of this Handler?

The
ELSE
'rest of code here
end

The 'rest of code here, the is the confusing part.

If ErrNumber > 0 Then
     ' You Error Handling Code goes here
Else
    ' DISPLAY THE PAGE!
End

That is where I need a little more guidance here.

(Hope this confusing question makes a little bit is sense
Big MontyWeb Ninja at largeCommented:
another alternnative solution would be, if you have access to IIS, is set up a custom error page, the nadd your error handling in there. This way, it would affect ALL of your pages. You could also control whats sent out to the users browser. This all depends if you have access to IIS of course, but I thought I'd just throw it out there :)
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Wayne BarronAuthor, Web DeveloperAuthor Commented:
@the_big_daddy
I assume you did not read my starting post?
3rd line down...
>> I do not have access to the 500-100 pages (Please don'y ask, it is beyond me)
pateljituCommented:
Error generated when code is not able to connect to MSSQL server would be

err.description: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
err.number: -2147467259
err.source: Microsoft OLE DB Provider for ODBC Drivers

, and in which case err.number is negative value so when you try
Set ErrNumber = Err.Number
On Error GoTo 0
If ErrNumber > 0 Then

it will not work as expected. Try code as provided


<%

On Error Resume Next

Dim someSonnectionstring : someSonnectionstring = "Driver:{SQL SERVER}; Server=127.0.0.1"

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open(someSonnectionstring)


if instr(1, err.Description, "SQL Server does not exist or access denied.") > 0 then
	Response.Write("SQL server currently not available.") 
elseif err.number > 0 then
    Response.Write(err.Description &" Some other error occured.") 
Else
   set rs = conn.Execute("select top 10 * from sometablename")
   if not RS.eof then
        response.Write(rs("columnName") &" ")
   end if
End

%>

Open in new window

Wayne BarronAuthor, Web DeveloperAuthor Commented:
Hello pateljitu
Thanks for "reading" my initial post.

One question for you.

OK, This is my structure.

acn.asp => Database File (This holds several connection to different DB's all on the same server)
m.asp => This holds all the RS for all the data in the site
body.asp => This of course is the body, which displays all the data depending on the Query that is made, on what is displayed to the viewer.
foot.asp => This is the footer page, closing the DB connections and so forth.

NOW
My question is this: Running your script above the
ELSE

END

Where would I put the END at?
Would it go into the foot.asp page? As this is the last step of the page.


Also.
Running just the word :  END
Gives an error that it is missing the IF.... as in: END IF

Is there something that needs to be added to make it end with just END?

Thanks for the time.
Carrzkiss
pateljituCommented:
Yes, based on your requirement on what to display to user you can have END IF on foot.asp page.

And correction on my part, statement will require END IF instead of just END

So code would be something like this:

if instr(1, err.Description, "SQL Server does not exist or access denied.") > 0 then
would be on page m.asp (guessing this where connection is opened)

Else would be on body.asp page

End if will be in foot.asp page.

As a suggestion for better code debugging option, you can have this code
dim ErrorMessage
if instr(1, err.Description, "SQL Server does not exist or access denied.") > 0 then
      ErrorMessage = "SQL server currently not available."
end if

in m.asp page and
on body.asp page check if there is errorMessage

If errorMessage = "" then
 do database record display
else
 display Error message.
end if

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wayne BarronAuthor, Web DeveloperAuthor Commented:
What the plan is, is to send an email to me letting me know that it an error accured with the db.
The MAIN concern, is keeping the visitors from seeing any of these errors.

I will give what you have provided a test later on this evening.

One more Question for you please.

As I stated above, I DO NOT have access to the 500-100 page
(I have access to EVERYTHING else, except that one,,, don't ask)

I want to stop the visitors from viewing any possible errors what-so-ever
I know that would probably require a LOT of coding on my page.
(or) maybe not, depending on what is required.

Is it possible to use what you have provided to capture ALL errors that steam from the ASP?

In your example above

elseif err.number > 0 then
    Response.Write(err.Description &" Some other error occured.")

Would this capture the other asp errors? Or is this strickly SQL Server only?

Thanks a BUNCH for your time.
I really need to get these errors grabbed up and sent to me so that I can fix issues instead of having these ugly errors shown to the visitors.

Carrzkiss
pateljituCommented:
You have limited options without 500;100 page, because you can in this case use server.getLastError() which helps with error description, line number, source.

To suggest use this sample, bit tricky as you would need to add this on every secnario which can fail and you need to trap error.

if cInt(err.number) then
        strErrorMsg = "number: "& err.number &"&msg="& err.Description &"&fileName="& request.ServerVariables("PATH_INFO")
        Response.Redirect("http://www.example.com/errorpage.asp?" & strErrorMsg)
       Response.End
End if


This sample will help you to redirect to a errorpage with querystring that you can capture and write code to send email with error details (which in this is very llimited).

to your question "Would this capture the other asp errors? Or is this strickly SQL Server only?", Yes it will capture other ASP erros. But this is not the best way to keep track of error on website (which in your case is no option), as err.number is set to new value on every error encountered (unless you stop at first error encounter and redirect to error page).
Wayne BarronAuthor, Web DeveloperAuthor Commented:
This is a pain.
The hosting provider basically does not know how to use their system to set it up so we have access to the 500;100 page. A bunch of idiots if you ask me.
But hopefully is things go the way they are starting to, then I will not have to put up with them bu for another 6 months, and then I will be hosting in-house with my company.

Thank you, I will try to test the main code here after while, right now I have an issue I have to tend to, so this should be wrapped up either this evening or first thing tomorrow.

Carrzkiss
Wayne BarronAuthor, Web DeveloperAuthor Commented:
Forgot all about this one.
Sorry guys.

Carrzkiss
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.