Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 24th, 2004, 04:18 PM
Authorized User
 
Join Date: Mar 2004
Location: , , .
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?

Reply With Quote
  #2 (permalink)  
Old September 24th, 2004, 07:14 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
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
Reply With Quote
  #3 (permalink)  
Old September 24th, 2004, 08:28 PM
Authorized User
 
Join Date: Mar 2004
Location: , , .
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>
Reply With Quote
  #4 (permalink)  
Old September 25th, 2004, 09:11 AM
Authorized User
 
Join Date: Mar 2004
Location: , , .
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!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:29 AM.


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