Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 24th, 2004, 04:18 PM
Authorized User
 
Join Date: Mar 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gmoney060 Send a message via MSN to gmoney060
Default Global.asa

How do you connect to a database in the Global.asa file? And collect values and such?

 
Old September 24th, 2004, 07:14 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

The same as you connect in a regular .asp file without using any includes, attempting to send headers or writting to the browser in any way (a little harder to track any errors). The following is an example of working a hit counter. After changing the obvious variables it is a cut n paste piece of code.

NOTE:
1..The application.lock and application.unlock, This is important, I believe to accomodate any active sessions/applications on execution.

2..To carry values from this page forward use session vars

--------------------------
sub session_onStart
    Session.Timeout = 40
    session("osirType") = 2
    session("osirTypeName") = "Ship Safe"
    application.lock
      Set Conn = Server.CreateObject("ADODB.Connection")
      GetConnectionString = "Provider=SQLOLEDB.1; " & _
      "Password=yourPassword; Persist Security Info=True; User ID=userName;Initial Catalog=dataStoreName; Data Source=PCName"
      Conn.Open GetConnectionString
      sql = "SELECT hits FROM hits WHERE id=1"
      set getInfo = conn.execute(sql)
      SQL = "update hits SET hits=" & cint(getInfo(0) + 1) & " WHERE id=1"
      Conn.execute(SQL)
      Conn.close
       set Conn = nothing
    application.unlock
End Sub
-------------------------------------



Wind is your friend
Matt
 
Old September 24th, 2004, 08:28 PM
Authorized User
 
Join Date: Mar 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gmoney060 Send a message via MSN to gmoney060
Default

This is what I have now, but i keep on getting the error "not a valid filename". The line that is in red is the line that the error is pointing too.

Code:
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
'sets up the connection to the databases needed in the script


Sub Application_OnStart
    ' Set our user count to 0 when we start the server
    Application("ActiveGuests") = 0
End Sub

Sub Session_OnStart
    ' Checks to see if the user is already logged in
    If Session("TDCUser") = "" Or Request.Cookies("TDCUser") = "" Then
    Application.Lock
        Application("ActiveGuests") = Application("ActiveGuests") + 1
    Application.UnLock
    End If
    If Session("TDCUser") = "" Then
        If Request.Cookies("TDCUser") <> "" Then
            Dim ObjConn : ObjConn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=http://www.topdeckcards.com/fpdby/database.mdb"
            Dim CheckUser : Set CheckUser = Server.CreateObject("ADODB.RecordSet")
            CheckUser.Open "Select * From UserStats Where UserName='"&Request.Cookies("TDCUser")&"'",ObjConn,1,2
            Session("TDCUser") = CheckUser("UserName")
            Session("TDCGroup") = CheckUser("GroupID")
        End If
    End if
End Sub

Sub Session_OnEnd
    ' Decrease the active visitors count when the session ends.
    If Session("TDCUser") <> "" Then
        Dim ObjConn : ObjConn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=http://www.topdeckcards.com/fpdby/database.mdb"
        Dim UpdateUser : Set UpdateUser = Server.CreateObject("ADODB.RecordSet")
        UpdateUser.Open "Select * From UserStats Where UserName="&Session("TDCUser"),ObjConn,1,2
        UpdateUser("LoggedIn") = False
        UpdateUser.Update
        UpdateUser.Close
        Set UpdateUser = Nothing
    Else
        Application.Lock
            Application("ActiveGuests") = Application("ActiveGuests") - 1
        Application.UnLock
    End If
End Sub




</SCRIPT>
 
Old September 25th, 2004, 09:11 AM
Authorized User
 
Join Date: Mar 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gmoney060 Send a message via MSN to gmoney060
Default

i figured it out, thanks though!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Global.asa pushpa Classic ASP Basics 19 March 9th, 2007 08:30 AM
global.asa vin_0x1 Classic ASP Components 2 July 24th, 2006 01:13 AM
GLOBAL.ASA zaeem Classic ASP Databases 3 November 4th, 2003 09:13 AM
Global.asa madsmad ASP.NET 1.0 and 1.1 Basics 1 August 17th, 2003 07:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.