Automatically refresh page and revert url to previous page in asp

Hi E.E

To explain I have a script ( that i was kindly helped with) that checks the connection to a database, if it's unable to connect it redirects the customer to an error page that does not require a connection. i'd like to refresh the error page say every 10 seconds, and on the refresh go back to the page where the customer previously was, thus running this procedure untill it connects.

a) Would this be the most efficent way of checking that the connection is now available, by posting back to the original page, loading that page if it fails go back to the error page and repeating the process, or by checking the connection on the error page and once it can connect then redirect the url to the customers original page?

b) I use a global.asa, would it be correct to say i need to create a session variable within that, that could grab and store the current page url, so the error page knows where to return to?

This is deeper than im used to so any help is great.
Thanks
DanielR6Asked:
Who is Participating?
 
DanielR6Author Commented:
It seems I now solved it, whether its correct or not im not sure but it works. I was using a response.redirect to transfer the page over to a busy page if the database couldn't connect, however i also created a session variable to store the previous page using HTTP_REFFER. I later found  that the redirect doesnt store in the browser so the reffer can't pick it up, but server.transfer does.

This is the complete code I have. It can probably be much improved on though. Please post improvements if you do.
---------------  global-functions.asp ---------------
 
Place this in an include file for every page that connects to the database;
 
<%
Session("currentpage")= Request.ServerVariables("SCRIPT_NAME")
%>
 
<%
Dim strConnString
Dim db
sub dbconnect(blnswitch)
	Select Case blnswitch
	Case 1
		
		On Error Resume Next
		
                  'Connection name stored in global.asa
		strConnString = Application("ConnName") 
 
		set db = CreateObject("ADODB.Connection")
		
		db.Errors.Clear
		Err.Clear
		db.Open strConnString
		
	Case 0
		db.close
		set db = nothing
	End Select
 
	'Error Handler
	If Err.Number <> 0 Then
            'Clear response buffer
 	    
	Response.Expires = 0 
    Response.Buffer = true 
	Response.Clear
 			
 	    'Redirect the page to the error page
			Server.Transfer("error.asp")
 
 
        End If
 
end sub
%>
 
---------------  global-functions.asp end ---------------
 
---------------  global.asa ---------------
<script language="vbscript" runat="server">
Sub Session_OnStart
	
	'connection string to database
    Application("ConnName") = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Mid(Server.MapPath("\"), 1, InStrRev(Server.MapPath("\"),"\")-1) & "mydatabase.mdb;"
	
End Sub
 
Sub Session_OnEnd
	
End Sub
 
Sub Application_OnStart
 
End Sub
</script>
---------------  global.asa end ---------------
 
---------------  error.asp --------------------
 
This goes on holding page;
 
<script type="text/javascript" />
var refreshinterval=5
var displaycountdown="yes"
var starttime
var nowtime
var reloadseconds=0
var secondssinceloaded=0
// Name of session stored in 
var n="<%Session("currentpage")%>";
 
 
function starttime() {
	starttime=new Date()
	starttime=starttime.getTime()
    countdown()
}
 
function countdown() {
	nowtime= new Date()
	nowtime=nowtime.getTime()
	secondssinceloaded=(nowtime-starttime)/1000
	reloadseconds=Math.round(refreshinterval-secondssinceloaded)
	if (refreshinterval>=secondssinceloaded) {
        var timer=setTimeout("countdown()",1000)
		if (displaycountdown=="yes") {
			window.status="Page refreshing in "+reloadseconds+ " seconds"
		}
 
    }
    else {
        clearTimeout(timer)
		location.href= (n)
 
    } 
}
window.onload=starttime
 
</script>
---------------  error.asp end -----------------

Open in new window

0
 
rentoncCommented:
Hi DanielR6,

Would you would need to do is use some javascript in the asp page to count down the refresh and send the user to the other page.
You can use the setTimeout() function in Javascript.

Chris
0
 
DanielR6Author Commented:
Hi again, oh ok, do i still need to setup a session variable storing the customers original page or would javascript cater for that to?

Dan
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
rentoncCommented:
You could simply use querystrings for the original page variable because each of your pages is ASP and can read the querystring collection.
0
 
DanielR6Author Commented:
I found this script, which does the refresh job. Though i have no idea how to include the querystring?
 I take it this could be done with session variables though? I only ask as thats something I'd like to play around with.
var refreshinterval=8
var displaycountdown="yes"
var starttime
var nowtime
var reloadseconds=0
var secondssinceloaded=0
 
function starttime() {
	starttime=new Date()
	starttime=starttime.getTime()
    countdown()
}
 
function countdown() {
	nowtime= new Date()
	nowtime=nowtime.getTime()
	secondssinceloaded=(nowtime-starttime)/1000
	reloadseconds=Math.round(refreshinterval-secondssinceloaded)
	if (refreshinterval>=secondssinceloaded) {
        var timer=setTimeout("countdown()",1000)
		if (displaycountdown=="yes") {
			window.status="Page refreshing in "+reloadseconds+ " seconds"
		}
    }
    else {
        clearTimeout(timer)
		window.location.reload(true)
    } 
}
window.onload=starttime

Open in new window

0
 
DanielR6Author Commented:
Hi rentonc,

I've been looking at this for sometime now and havn't been able to come up with a fully working solution. So far i have this, but there are some glitches.

I don't know whether it was right to but I added window.history.go(-1) to the else statement to send the page back one step in the history which seems to sort of work, I also changed;  

'Display Error Message to user      
Response.write "An error occurred"
End If

from the pervious piece of code you gave me to ;
'Display Error Message to user
Response.Redirect Server.HTMLEncode("/error_docs/busy.asp")
End If

To send them to the error page if the connection can't be made to the database. The problem I get is that the page on error does go to the error holding page, and the page refreshes untill the connection is available, but when it goes back it seems to jump more than one step back, it goes to the orginal page rather than the page that is trying to be accessed. Im not sure but could it be because if a page gets clicked on, but the connection is down so gets redirected to the holding page it hasn't yet been visited, so its not in the browsers history.

I have also added a session variable to the global.asa if we were able to go down that route.

A bit of assistance on this would be appreciated.

Dan
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.