Global.asa and Declaring Objects

Results 1 to 5 of 5

Thread: Global.asa and Declaring Objects

  1. #1
    RGibson Guest

    Default Global.asa and Declaring Objects

    Hello all,<BR><BR>I have a db table that has the following fields:<BR>EmpID<BR>LoginID<BR>FirstName<BR>LastNa me<BR><BR>When a user logs on to our Intranet, I use Request.ServerVariables("AUTH_USER") to retrieve their username. I need an Application variable equal to that users employee id.<BR><BR>I&#039ve read numerous warnings about creating objects in the global.asa and I was wondering if the following would be safe:<BR>========================================= ======================<BR>Sub Application_OnStart<BR><BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>objConn .open "DSN"<BR>Set objRS = Server.CreateObject("ADODB.Recordset")<BR>strSQL = "SELECT EmpID FROM Users WHERE LoginID = &#039" & Request.ServerVariables("AUTH_USER") & "&#039"<BR><BR> strSQL, objConn, adOpenDynamic, adLockOptimistic, adCmdText<BR><BR>Application("User") = objRS("EmpID")<BR><BR>objRS.close<BR>Set objRS = Nothing<BR>objConn.close<BR>Set objConn = Nothing<BR><BR>End Sub<BR>=========================================== ====================<BR><BR>Thanks in advance!<BR><BR>-rg<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Global.asa and Declaring Objects

    Application variables hold constant for the entire time that the application is running and aren&#039t specific to indivisual users, so that code would not work. If you do the exact same thing in the Session_OnStart, however, and use a Session variable to hold the data as opposed to an Application variable, it will work fine.

  3. #3
    RGibson Guest

    Default RE: Global.asa and Declaring Objects (Correcting)

    Instead of Application_OnStart, I meant to use Session_OnStart<BR><BR>Thanks,<BR><BR>-rg

  4. #4
    RGibson Guest

    Default RE: Global.asa and Declaring Objects

    So there is no problem with creating those objects in the global.asa as long as they are killed when I&#039m finished using them?<BR><BR>Thanks for your help!<BR><BR>-rg

  5. #5
    Ian Stallings Guest

    Default RE: Global.asa and Declaring Objects (Correcting)

    This should work fine. It&#039s only a problem when you try<BR>to store the object reference in the application object<BR>or session object like this:<BR><BR><BR>set objTest = server.createobject("object.Test")<BR>Application( "test") = objTest<BR><BR><BR>So your code is fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts