|
 |
asp_web_howto thread: global.asa
Message #1 by "Shahid M. Syed" <shami_shah@h...> on Wed, 4 Sep 2002 13:05:04 +0500
|
|
Hello there !
I've been trying to make a website that keeps an individual record of user's visits. The user's visit count is initially read from
database into session variable where it is updated with new visits. When the user logs out or the session is terminated the values
held in session variables are written back into the database.
In the same way I'm using application variable to maintain site's visits in total.
I've tested the code for each section and its working OK in asp pages, but when I put them in global.asa it don't seems do anything.
Can you tell me what I'm doing wrong ?
The global.asa file is:
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnStart
Application("Online") = 0 ' Users online
Dim objConn, rsUsers
Set objConn = Server.CreateObject("ADODB.Connection")
Set rsUsers = Server.CreateObject("ADODB.Recordset")
Dim strDatabaseType
strDatabaseType = "Access"
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\datastores\info2u.mdb;" & _
"Persist Security Info=False"
rsUsers.Open "SiteVisits", objConn, adOpenForwardOnly, adLockReadOnly, adCmdTable
Application("VisitsTotal") = rsUsers("Site") ' Loading current site stats from database.
Application("VisitsPage01") = rsUsers("Page01")
Application("VisitsPage02") = rsUsers("Page02")
Application("VisitsPage03") = rsUsers("Page03")
Application("VisitsPage04") = rsUsers("Page04")
Application("VisitsPage05") = rsUsers("Page05")
rsUsers.Close
objConn.Close
Set rsUsers = Nothing
Set objConn = Nothing
End Sub
Sub Application_OnEnd
<!-- METADATA TYPE="typelib"
FILE="D:\Program Files\Common Files\System\ado\msado15.dll" -->
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source= D:\datastores\info2u.mdb"
Dim rsUsers
Set rsUsers = Server.CreateObject("ADODB.Recordset")
rsUsers.Open "SiteVisits", objConn, adOpenForwardOnly, adLockOptimistic, adCmdTable
rsUsers("Site") = Application("VisitsTotal") ' Updating site database with new visits
rsUsers("Page01") = Application("VisitsPage01")
rsUsers("Page02") = Application("VisitsPage02")
rsUsers("Page03") = Application("VisitsPage03")
rsUsers("Page04") = Application("VisitsPage04")
rsUsers("Page05") = Application("VisitsPage05")
rsUsers.Update ' update the database
Application.Contents.RemoveAll
End Sub
Sub Session_OnStart
Application.Lock
Application("Online") = Application("Online") + 1 ' Adding 1 to online users.
Application.UnLock
Session("VisitsTotal") ' just initialising the session variables.
Session("VisitsPage01")
Session("VisitsPage02")
Session("VisitsPage03")
Session("VisitsPage04")
Session("VisitsPage05")
End Sub
Sub Session_OnEnd
Application.Lock
Application("Online") = Application("Online") - 1
Application.UnLock
<!-- METADATA TYPE="typelib"
FILE="D:\Program Files\Common Files\System\ado\msado15.dll" -->
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source= D:\datastores\info2u.mdb"
Dim rsUsers
Set rsUsers = Server.CreateObject("ADODB.Recordset")
rsUsers.Open "MemberVisits", objConn, adOpenForwardOnly, adLockOptimistic, adCmdTable
rsUsers.Filter = "MemberID = '" & Session("MemberID") & "'"
' selecting appropriate user record
rsSVisits("Site") = Session("VisitsTotal") ' Updating user database with new visits
rsSVisits("Page01") = Session("VisitsPage01")
rsSVisits("Page02") = Session("VisitsPage02")
rsSVisits("Page03") = Session("VisitsPage03")
rsSVisits("Page04") = Session("VisitsPage04")
rsSVisits("Page05") = Session("VisitsPage05")
rsSVisits("Active") = False
rsSVisits("LastVisit") = Now
rsUsers.Update ' update the database
Session.Contents.RemoveAll ' clear session variables
End Sub
</SCRIPT>
Message #2 by "Ken Schaefer" <ken@a...> on Thu, 5 Sep 2002 15:12:26 +1000
|
|
Which part isn't working?
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Shahid M. Syed" <shami_shah@h...>
Subject: [asp_web_howto] global.asa
: Hello there !
:
: I've been trying to make a website that keeps an individual record of
user's visits. The user's visit count is initially read from database into
session variable where it is updated with new visits. When the user logs out
or the session is terminated the values held in session variables are
written back into the database.
: In the same way I'm using application variable to maintain site's visits
in total.
: I've tested the code for each section and its working OK in asp pages, but
when I put them in global.asa it don't seems do anything. Can you tell me
what I'm doing wrong ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<snipped>
Message #3 by "Rohan Parkes" <rparkes@e...> on Sat, 7 Sep 2002 11:04:42
|
|
One possibility is that the folder you are placing global.asa in isn't
defined as an application root. You would have to define the folder as a
subweb, then create it as an application in IS Properties. Otherwise the
global.asa won't fire.
> Hello there !
I've been trying to make a website that keeps an individual record of
user's visits. The user's visit count is initially read from database
into session variable where it is updated with new visits. When the user
logs out or the session is terminated the values held in session
variables are written back into the database.
In the same way I'm using application variable to maintain site's visits
in total.
I've tested the code for each section and its working OK in asp pages,
but when I put them in global.asa it don't seems do anything. Can you
tell me what I'm doing wrong ?
The global.asa file is:
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnStart
Application("Online") = 0 ' Users online
Dim objConn, rsUsers
Set objConn = Server.CreateObject("ADODB.Connection")
Set rsUsers = Server.CreateObject("ADODB.Recordset")
Dim strDatabaseType
strDatabaseType = "Access"
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\datastores\info2u.mdb;" & _
"Persist Security Info=False"
rsUsers.Open "SiteVisits", objConn, adOpenForwardOnly, adLockReadOnly,
adCmdTable
Application("VisitsTotal") = rsUsers("Site") ' Loading current site
stats from database.
Application("VisitsPage01") = rsUsers("Page01")
Application("VisitsPage02") = rsUsers("Page02")
Application("VisitsPage03") = rsUsers("Page03")
Application("VisitsPage04") = rsUsers("Page04")
Application("VisitsPage05") = rsUsers("Page05")
rsUsers.Close
objConn.Close
Set rsUsers = Nothing
Set objConn = Nothing
End Sub
Sub Application_OnEnd
<!-- METADATA TYPE="typelib"
FILE="D:\Program Files\Common
Files\System\ado\msado15.dll" -->
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source= D:\datastores\info2u.mdb"
Dim rsUsers
Set rsUsers = Server.CreateObject("ADODB.Recordset")
rsUsers.Open "SiteVisits", objConn, adOpenForwardOnly,
adLockOptimistic, adCmdTable
rsUsers("Site") = Application("VisitsTotal") ' Updating site database
with new visits
rsUsers("Page01") = Application("VisitsPage01")
rsUsers("Page02") = Application("VisitsPage02")
rsUsers("Page03") = Application("VisitsPage03")
rsUsers("Page04") = Application("VisitsPage04")
rsUsers("Page05") = Application("VisitsPage05")
rsUsers.Update ' update
the database
Application.Contents.RemoveAll
End Sub
Sub Session_OnStart
Application.Lock
Application("Online") = Application("Online") + 1 ' Adding 1 to online
users.
Application.UnLock
Session("VisitsTotal") ' just initialising the session variables.
Session("VisitsPage01")
Session("VisitsPage02")
Session("VisitsPage03")
Session("VisitsPage04")
Session("VisitsPage05")
End Sub
Sub Session_OnEnd
Application.Lock
Application("Online") = Application("Online") - 1
Application.UnLock
<!-- METADATA TYPE="typelib"
FILE="D:\Program Files\Common
Files\System\ado\msado15.dll" -->
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source= D:\datastores\info2u.mdb"
Dim rsUsers
Set rsUsers = Server.CreateObject("ADODB.Recordset")
rsUsers.Open "MemberVisits", objConn, adOpenForwardOnly,
adLockOptimistic, adCmdTable
rsUsers.Filter = "MemberID = '" & Session("MemberID") & "'"
' selecting appropriate user record
rsSVisits("Site") = Session("VisitsTotal") ' Updating user database
with new visits
rsSVisits("Page01") = Session("VisitsPage01")
rsSVisits("Page02") = Session("VisitsPage02")
rsSVisits("Page03") = Session("VisitsPage03")
rsSVisits("Page04") = Session("VisitsPage04")
rsSVisits("Page05") = Session("VisitsPage05")
rsSVisits("Active") = False
rsSVisits("LastVisit") = Now
rsUsers.Update ' update
the database
Session.Contents.RemoveAll ' clear session variables
End Sub
</SCRIPT>
Message #4 by "Shahid Syed" <shami_shah@h...> on Mon, 16 Sep 2002 14:59:28
|
|
The problem is that i can't read from or write to database from global.asa.
All other instructions are executing properly.
Need Help ?
Message #5 by "Ken Schaefer" <ken@a...> on Tue, 17 Sep 2002 11:53:07 +1000
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Shahid Syed" <shami_shah@h...>
Subject: [asp_web_howto] Re: global.asa
: The problem is that i can't read from or write to database from
global.asa.
: All other instructions are executing properly.
:
: Need Help ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
That is because you are doing something wrong.
Cheers
Ken
Message #6 by "Keith Every" <keithe@e...> on Tue, 17 Sep 2002 08:51:51
|
|
Hi,
I am not sure about this but I have found that you can only do certain
things from the application_onstart. You caould try to move the code from
here into the session_onstart and running it only if the number of current
users is 0 (as initially initialised). A simular thing may be required
when the application ends.
Keith
> The problem is that i can't read from or write to database from
global.asa.
A> ll other instructions are executing properly.
> Need Help ?
|
|
 |