Solved

Problem with ASP, global.asa, updating to Database

Posted on 2006-07-13
5
410 Views
Last Modified: 2008-02-01
my website is my904.com 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!

--------------------------------------------------------------------------------------------global.asa
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
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)
          else
               ' 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
     loop
     ' map all URL= attributes in _ConnectionString variables
     Application.Lock
     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))
          next
     end if
     Application.Unlock
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)
     Else
          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",""
     Application.Lock
     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
                    next
                    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
     Next
     Application.Unlock
     Set oKnown = Nothing
End Sub
</SCRIPT>
<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:CustomDocumentProperties>
<mso:connectionstatus msdt:dt="string">myspace=1</mso:connectionstatus>
</mso:CustomDocumentProperties>
</xml><![endif]-->
</head>
0
Comment
Question by:vallowens
  • 3
  • 2
5 Comments
 
LVL 65

Expert Comment

by:rockiroads
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


0
 

Author Comment

by:vallowens
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
0
 
LVL 65

Expert Comment

by:rockiroads
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

0
 

Author Comment

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

Accepted Solution

by:
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
http://www.pageresource.com/jscript/j_a_02.htm

and this is more what may be want you want
http://dotnetjunkies.com/WebLog/familjones/archive/2004/04/06/10884.aspx

some useful JS stuff
http://www.irt.org/script/window.htm

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now