SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Global.asa

  1. #1
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Global.asa

    HI I am a asp newbie and I have a script which tracks the number of visitors and members to my site via application and session variables in the global.asp. Members who sign in are entered into a SQL server database table. My question is in global.asa how do i clean up the db table when the users session times out?
    I understand that I need to put some code in the Sub Session_onEnd().Do I need to create a connection to the database and then execute the delete command?. This is what I have so far

    Sub Session_onEnd()

    sqlstr = "DELETE FROM Login_T WHERE SessionID = " & Session.SessionID
    Set objCmd = Server.CreateObject("ADODB.Command")
    Set objCmd.ActiveConnection = objConn
    objCmd.CommandText = sqlstr
    objCmd.Execute

    End Sub

    any help appreciated

    cheers

  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That looks ok, except for one thing. The sessionID is not a garunteed unique number, each number can and will be used again.

    Also, you never showed you actual connection object. Please bear in mind that you can not use the server.mappath() function in a session_on... sub, you will either need to enter the full psysical (sp) path of the DSN name.

    Hope that helps


  3. #3
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Below is how I connect to the database should I enter this in the Sub Session_onEnd()before the databse query? Secondly if I wish to connect to the database to initalise stuff using Sub Session_onStart() Do I need to only show the connection object once or for both subs?

    sDSN = "dsn"
    sUserName = "me"
    sPassword = "password"
    sDBName = "dbname"
    sComputerName = "168.154.163.13"

    Set objConn = Server.CreateObject("ADODB.connection")
    sConn = "Provider=SqlOLEDB;Network Library=DBMSSOCN;" & _
    "Data Source=" & sComputerName & ";" &_
    "Initial Catalog=" & sDBName & ";" & _
    "User Id=" & sUserName & ";" &_
    "Password=" & sPassword & ";"

    objConn.Open sConn


    cheers

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will need to have the connection string in each sub.



Bookmarks

Posting Permissions

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