ADO code in Session_OnEnd not working eventhough S

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: ADO code in Session_OnEnd not working eventhough S

  1. #1
    Nelson Beaman Guest

    Default ADO code in Session_OnEnd not working eventhough S

    I know my Session_OnEnd code is running when a user&#039s session times out (I&#039ve tested it).<BR><BR>I know my ADO code works because I have tested it in a stand-alone ASP (not in the global.asa file) . This code simply changes a field value in my database.<BR><BR>I put this same code into the Session_OnEnd area of the global.asa file, but the field value in the database never gets changed eventhough I know Session_OnEnd runs when a user&#039s session times out.<BR><BR>Are there any issues with running ADO code in the global.asa file?<BR><BR>Any help would be greatly appreciated (and may even stop some of my hair from falling out!)<BR><BR><BR><BR>Here&#039s my Session_OnEnd code:<BR>---------------------------------------------------------------<BR>Sub Session_OnEnd<BR><BR> Const adLockOptimistic = 3<BR> Const adOpenKeyset = 1<BR><BR> Set Conn = Server.CreateObject("ADODB.Connection")<BR> Conn.Open "MYDATABASE"<BR><BR> Set Rs = server.createobject("ADODB.Recordset")<BR> set Rs.ActiveConnection = Conn<BR> <BR> SQLStmt = "UPDATE [Users] SET [UAvailable] = False WHERE ([UID]=16);"<BR> <BR> Rs.Open SQLStmt, , adOpenKeyset, adLockOptimistic<BR> <BR> Conn.Close<BR> set Rs=nothing<BR> set Conn=nothing<BR><BR> End Sub<BR>---------------------------------------------------------------

  2. #2
    Cable Guest

    Default RE: ADO code in Session_OnEnd not working eventhou

    Someone correct me if I am wrong, but doesn&#039t global.asa run before the ASP page? It doesn&#039t run after the ASP page? It is a one time thing and doesn&#039t stay in memory.<BR><BR>You might be better off sticking the code in an include file and then including it in the ASP page.

  3. #3
    Join Date
    Dec 1969
    Posts
    41

    Default RE: ADO code in Session_OnEnd not working eventhou

    I have used ADO in global.asa files and it works. Although I was using it in the onStart subs.<BR>Syntax errors will cause the file to not do what you think it should do, and you will get no error messages.<BR>How are you getting the 16 to pass to the sql statement? <BR>

  4. #4
    Nelson Beaman Guest

    Default RE: ADO code in Session_OnEnd not working eventhou

    For now I am hard-coding it. I have tested the VBScript ADO part as a stand-alone page so I know it works without syntax errors. Must be somthing I&#039m overlooking. Thanks for the response.


  5. #5
    Keith Fowler Guest

    Default RE: ADO code in Session_OnEnd (runs after also)

    Cable,<BR> The global.asa file runs many times. It runs when the app is started for the first time. This is the Application_OnStart event. Then each Session it runs the Session_OnStart event when a user enters the app, then it runs a second time when the user leaves. This is the Session_OnEnd event. And lastly, it runs when you shutdown the server with the Application_OnEnd event.<BR><BR>

  6. #6
    ASP_DRUG_DEALER Guest

    Default RE: ADO code in Session_OnEnd not working eventhou

    This maybe over my head, but I was trying to do this myself awhile back. Three newsgroups later and various message boards, someone posted "rethink your logic, its not going to happen". Well, with that _great_ advice in mind and a week of looking for an answer behind me. I did rethink and rewrite my script.<BR><BR>Like yourself, I could run my script as a stand alone, even as an include. I tried DSN&#039less connections and DSN&#039s ( I was reaching). Nothing worked in the Session_Onend, as far as a db is concerned. Don&#039t get me wrong, I could do alot in session_onend event, just nothing with a database.<BR><BR>Here&#039s my thinking on this....<BR>In the session_onstart you can create objects, such as a db connection if you wanted to. Well, IIS says "someone wants us to make an object, lets do it". So IIS creates this object that has some type of "ID" that corresponds to the user that made the request. We may not know about this ID, but I have a feeling there is one (again, my thinking). This brings me to the session_onend event and IIS. IIS cannot create an object when it does not have this ID (user) to assign it to. A user session ends and also their "ID" is gone, then IIS fires off the session_onend event.<BR><BR>This is just my thinking. I am hoping someone will read this and tell me I am on drugs and that you can write stuff to the database on the session_onend event. That would certainly make me happy also. <BR><BR>ASP_DRUG_DEALER

  7. #7
    Join Date
    Dec 1969
    Posts
    21

    Default You are not executing the SQL

    You are just opening the recordset with the sql statement you have written. You need to execute it my dear. Here is the code :<BR><BR>Sub Session_OnEnd<BR><BR>Set Conn = Server.CreateObject("ADODB.Connection")<BR>Conn.Op en "MYDATABASE"<BR><BR>SQLStmt = "UPDATE [Users] SET [UAvailable] = False WHERE ([UID]=16);"<BR><BR>Conn.Execute SQLstmt<BR><BR>Conn.Close<BR>set Conn=nothing<BR><BR>End Sub<BR><BR>This has to work.

  8. #8
    ASP_DRUG_DEALER Guest

    Default RE: HELL YEA! JRD is the MAN!!

    I have been trying to do this for a while now. Read my post above. I look back at it, now I know I am on drugs. Anyways what I did was make a simple access db throw a few records in there. Copy your script, with a few changes (DSN and SQL text). Set session.timeout to 1.....wait....wait....my harddrive spins a little. Check the DB...NO FREAKING RECORDS!!<BR><BR>Killer! Sorry about the title, but this works!! Even on PWS and 98!<BR>&#060;SCRIPT LANGUAGE=VBScript RUNAT=Server&#062;<BR>SUB Session_OnEnd<BR>Set Conn = Server.CreateObject("ADODB.Connection")<BR>Conn.Op en "tester"<BR>SQLStmt = "delete * from members"<BR>Conn.Execute SQLstmt<BR>Conn.Close<BR>set Conn=nothing<BR>END SUB<BR>&#060;/SCRIPT&#062;<BR>

  9. #9
    Join Date
    Dec 1969
    Posts
    760

    Default RE: ADO code in Session_OnEnd -you must have an er

    You can do stuff to your DB in the session onend.<BR>I have done it, it works.<BR><BR>This is the code from the Global.asa<BR>The DB is SQL Server.<BR>Yes, I tested it immediately before posting.<BR><BR>Sub Session_OnEnd<BR>&#039 Empty shopping basket at end of session and return cards to inventory<BR> Dim Conn<BR> Set Conn = Server.CreateObject("ADODB.Connection")<BR> Conn.ConnectionTimeout = Application("MagicConn_ConnectionTimeout")<BR> Conn.CommandTimeout = Application("MagicConn_CommandTimeout")<BR> Conn.Open Application("MagicConn_ConnectionString"), _<BR> Application("MagicConn_RuntimeUserName"),_<BR> Application("MagicConn_Password")<BR> strSQLGetBasketContents = "SELECT InvCardID,BasketCardQuantity" & _<BR> " FROM ShoppingBasket " & _<BR> " WHERE UserID = " & Session("UserID")<BR> Set recBasketContents = Conn.Execute(strSQLGetBasketContents)<BR> While not recBasketContents.EOF<BR> strSQLReturnToInventory = "UPDATE Inventory" & _<BR> " SET InvCardQuantity = InvCardQuantity + " & _<BR> recBasketContents("BasketCardQuantity") & _<BR> " WHERE InvCardID = " & recBasketContents("InvCardID")<BR> Conn.Execute(strSQLReturnToInventory) <BR> recBasketContents.MoveNext<BR> Wend <BR>&#039* Remove Items from ShoppingBasket <BR> strSQLDelete = "DELETE FROM ShoppingBasket WHERE UserID = " & Session("UserID")<BR> Conn.Execute strSQLDelete<BR><BR>End Sub<BR>

  10. #10
    Join Date
    Dec 1969
    Posts
    118

    Default RE: You are not executing the SQL

    Now I am really confused. This whole thread is probably over my head, but I can&#039t help commenting on your reply. I have written many, many asp pages that issue SQL to all sorts of Data Bases. Oracle, Access, SQL Server, etc and every man jack of them use the RS.Open method shown in the original post, instead of the Conn.Execute method(which I have no doubt is valid, I just didn&#039t learn it that way).<BR> I have never done it from global.asa however, so I can&#039t enter the discussion in any other way.

Posting Permissions

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