Problem with ASP, global.asa, updating to Database

Posted on 2006-07-13
Last Modified: 2008-02-01
my website is when users log in it automatically set database table USERS= Online=true therefore showing them as online now as you can see if you go to the browse page, if they click the logout button it sets them Online=false, problem is if they hit the X button on browser they stay logged in forever or until i manually go in the database! keep in mind i picked up an ASP book 2 months ago and created this site from scratch i have no prior html or asp experience so please basic terms not to technical.

2nd: when users login in the session logs them out in about 5-10 minutes im enclosing a copy of my global.asa file. Please help, my investors are on my tail bout these 2 problems.
Should've went to school huh, not booksamillion!

Sub Application_OnStart
     '==FrontPage Generated - startspan==
     Dim FrontPage_UrlVars(2)
     '--Project Data Connection
          Application("myspace_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=*********/*********.mdb"
          FrontPage_UrlVars(0) = "myspace_ConnectionString"
          Application("myspace_ConnectionTimeout") = 60
          Application("myspace_CommandTimeout") = 30
          Application("myspace_CursorLocation") = 3
          Application("myspace_RuntimeUserName") = ""
          Application("myspace_RuntimePassword") = ""
     '--Project Data Connection
          Application("myspaces_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=***********/*********.mdb"
          FrontPage_UrlVars(1) = "myspaces_ConnectionString"
          Application("myspaces_ConnectionTimeout") = 60
          Application("myspaces_CommandTimeout") = 30
          Application("myspaces_CursorLocation") = 3
          Application("myspaces_RuntimeUserName") = ""
          Application("myspaces_RuntimePassword") = ""
     Application("FrontPage_UrlVars") = FrontPage_UrlVars
     '==FrontPage Generated - endspan==
End Sub
Sub Session_OnStart
     FrontPage_StartSession '==FrontPage Generated==
     FrontPage_ConvertFromODBC '==FrontPage Generated==
End Sub
Sub FrontPage_StartSession
     On Error Resume Next
     if Len(Application("FrontPage_VRoot")) > 0 then Exit Sub
     sFile = "global.asa"
     sRootPath = Request.ServerVariables("APPL_PHYSICAL_PATH")
     if Left(sRootPath,1) = "/" then sSep = "/" else sSep = "\"
     if Right(sRootPath,1) <> sSep then sRootPath = sRootPath & sSep
     sRootPath = sRootPath & sFile
     ' discover the VRoot for the current page;
     ' walk back up VPath until we match VRoot
     Vroot = Request.ServerVariables("PATH_INFO")
     iCount = 0
     do while Len(Vroot) > 1
          idx = InStrRev(Vroot, "/")
          if idx > 0 then
               Vroot = Left(Vroot,idx)
               ' error; assume root web
               Vroot = "/"
          end if
          if Server.MapPath(Vroot & sFile) = sRootPath then exit do
          if Right(Vroot,1) = "/" then Vroot = Left(Vroot,Len(Vroot)-1)
          iCount = iCount + 1
          if iCount > 100 then
               ' error; assume root web
               Vroot = "/"
               exit do
          end if
     ' map all URL= attributes in _ConnectionString variables
     if Len(Application("FrontPage_VRoot")) = 0 then
          Application("FrontPage_VRoot") = Vroot
          UrlVarArray = Application("FrontPage_UrlVars")
          for i = 0 to UBound(UrlVarArray)
               if Len(UrlVarArray(i)) > 0 then FrontPage_MapUrl(UrlVarArray(i))
     end if
End Sub
Sub FrontPage_MapUrl(AppVarName)
     ' convert URL attribute in conn string to absolute file location
     strVal = Application(AppVarName)
     strKey = "URL="
     idxStart = InStr(strVal, strKey)
     If idxStart = 0 Then Exit Sub
     strBefore = Left(strVal, idxStart - 1)
     idxStart = idxStart + Len(strKey)
     idxEnd = InStr(idxStart, strVal, ";")
     If idxEnd = 0 Then
          strAfter = ""
          strURL = Mid(strVal, idxStart)
          strAfter = ";" & Mid(strVal, idxEnd + 1)
          strURL = Mid(strVal, idxStart, idxEnd - idxStart)
     End If
     strOut = strBefore & Server.MapPath(Application("FrontPage_VRoot") & strURL) & strAfter
     Application(AppVarName) = strOut
End Sub
Sub FrontPage_ConvertFromODBC
     On Error Resume Next
     if Len(Application("ASP_OS")) > 0 then exit sub
     str = "_ConnectionString"
     slen = Len(str)
     set oKnown = Server.CreateObject("Scripting.Dictionary")
     oKnown.Add "DRIVER",""
     oKnown.Add "DBQ",""
     oKnown.Add "SERVER",""
     oKnown.Add "DATABASE",""
     oKnown.Add "UID",""
     oKnown.Add "PWD",""
     For each item in Application.Contents
          if UCase(Right(item,slen)) = UCase(str) then
               sName = Left(item,Len(item)-slen)
               sConn = Application(item)
               if InStr(LCase(sConn),"provider=") < 1 and Len(Application(sName & "_ConnectionTimeout"))>0 then
                    sArr = Split(sConn,";")
                    set oDict = Server.CreateObject("Scripting.Dictionary")
                    bUnknown = False
                    for i = 0 to UBound(sArr)
                         s = sArr(i)
                         idx = InStr(s,"=")
                         sKey = UCase(Trim(Left(s,idx-1)))
                         sVal = Trim(Mid(s,idx+1))
                         oDict.Add sKey, sVal
                         if Not oKnown.Exists(sKey) then bUnknown = True
                    if bUnknown = False and oDict.Exists("DRIVER") then
                         sDrv = oDict.Item("DRIVER")
                         sNew = ""
                         if InStr(sDrv,"Microsoft Access") > 0 and oDict.Exists("DBQ") and not (oDict.Exists("UID") or oDict.Exists("PWD")) then
                              sNew = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & oDict.Item("DBQ")
                         elseif InStr(sDrv,"SQL Server") > 0 and oDict.Exists("SERVER") and oDict.Exists("DATABASE") then
                              sNew = "Provider=SQLOLEDB;Data Source=" & oDict("SERVER") & ";Initial Catalog=" & oDict("DATABASE")
                              if oDict.Exists("UID") then sNew = sNew & ";User ID=" & oDict("UID")
                              if oDict.Exists("PWD") then sNew = sNew & ";Password=" & oDict("PWD")
                         end if
                         if sNew <> "" then
                              Application(item) = sNew
                         end if
                    end if
                    set oDict = Nothing
               end if
          end if
     Set oKnown = Nothing
End Sub
<head><title>Web Site Settings for Active Server Pages</title><html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<!--[if gte mso 9]><xml>
<mso:connectionstatus msdt:dt="string">myspace=1</mso:connectionstatus>
Question by:vallowens
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
  • 3
  • 2
LVL 65

Expert Comment

ID: 17106065
How is your Javascript?

Use the onUnLoad function to capture a window closure,

Alternative is on your site, you have your home page, which pops up a new window, this new window has no close button/no toolbar etc
And u access your site thru that


Author Comment

ID: 17107526
Ive tried the onUnload feature but i need the the unOnload to only work when the users click the X on the browser not switch to another page or hit refresh! I know it can be done because when ya get certain popups when ya hit X they redirect you to another page
LVL 65

Expert Comment

ID: 17108555
Yes, but I thought they used tthe onUnLoad function for that

I didnt realise refresh causes that

With regards to switching to another page, what about this

create a variable in your javascript, say call it exitFlag
initialise to 1

Now instead of using A HREF, call a javascript function which sets exitFlag to 0 then loads your new page

On the unload event, check exitFlag, if 1, then u know they are exiting, if 0 then they have clicked a link


Author Comment

ID: 17108897
cool is it anyway u can giv me an example of this? it would be much appreciated
LVL 65

Accepted Solution

rockiroads earned 500 total points
ID: 17111837
No probs
I had better give u some links instead so u can do some reading up on this

and this is more what may be want you want

some useful JS stuff


Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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