PDA

View Full Version : Global.asax


jgs3
04-01-2005, 04:34 AM
Hello,

I am looking for anybody who migh have an example of loading data from a database during the Application_Start in the Global.asax file. I simply want to pick the values from the DB and use them to set Application variables for all my pages to use. I was trying to use static variables [cache("varName") = varValue] but couldn't get that to work either. ANy hepl would be appreciated...

Jim

yorkshirela
04-05-2005, 02:50 AM
Jim, you are not going to accomplish what you are looking for by declaring local variable in the Application_Start method. You can either declare them Public Static at a class level or you can use Session variables. </o:p>
If you declare them at the class level (Public Static) you are going to need to instantiate the Global class any time you want to use them.</o:p>
Please let me know if you need more details.</o:p>


Marcelo.

jgs3
04-11-2005, 07:20 AM
Thanks but the Application variables are working when set in Global.asax as in:


<%@ Import Namespace="System.Web.Caching" %>


<script language="vb" runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Application("AllUniqueSessions") = 0
Application("NextPrezCon") = #02/22/2006#
Application("gmcutoff") = #09/30/2005#
Application("playercutoff") = #01/30/2006#


End Sub


Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
Application("AllUniqueSessions") += 1
End Sub


Sub Session_Stop(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is stopped
Application("AllUniqueSessions") -= 1
End Sub
</script>

I was looking for examples of how to load the values into the Application variables upon Application_Start.