Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. 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 Professional 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 October 26th, 2007, 01:39 PM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sub Session_OnStart!!?

this code works! it puts the 1 in field "online"
if i will open asp file with that code alone and i will enter this asp with session it will give me "1" perfectly!
Code:
dim mysql, connasa, connstringasa
Set connasa = Server.CreateObject("ADODB.Connection")
ConnStringasa = "Driver={MySQL ODBC 3.51 Driver};Server=mySQL4.domain.com;database=user;user=user;password=pass;OPTION=3"                        

Connasa.Open ConnStringasa

if Session("usernameid")<>"" then

vab=Session("usernameid")

 mySQL="UPDATE crmagents SET online=1 WHERE username='" & vab & "'"

connasa.execute(mySQL)

end if

Connasa.close
but when i put the same code in the global.asa
like this

Code:
<script language="vbscript" runat="server">
Sub Session_OnStart
dim mysql, connasa, connstringasa
Set connasa = Server.CreateObject("ADODB.Connection")
ConnStringasa = "Driver={MySQL ODBC 3.51 Driver};Server=mySQL4.domain.com;database=user;user=user;password=pass;OPTION=3"                        

Connasa.Open ConnStringasa

if Session("usernameid")<>"" then

vab=Session("usernameid")

 mySQL="UPDATE crmagents SET online=1 WHERE username='" & vab & "'"

connasa.execute(mySQL)

end if

Connasa.close
end sub
</script>
when i enter pages with the right sessions...i got nothing...just like it not works...
why? whyyyy me?:)

 
Old October 27th, 2007, 06:22 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the problem is that when the user login and and get the Session("usernameid") the globla.asa not recognize the session...
i tested it 2 ways- to give the Session("usernameid")=username and only than to redirect the page
and the second way i first redirected the user and only then on the redirected page i gave Session("usernameid")=session("username")

and on the global i changed the "if" into:
if Session("usernameid")<>"" or Session("username")<>"" then



 
Old October 27th, 2007, 06:29 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Session_OnStart fires, as its name suggests, at the start of a new session. So this:
Code:
Sub Session_OnStart

  ...
  If Session("usernameid") <> "" Then
  doesn't really make sense. The session is just created so Session("usernameid") will never have a value because you haven't set it yet.

HtH,


Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004




Similar Threads
Thread Thread Starter Forum Replies Last Post
db conn's via global.asax's session_onstart... deian ASP.NET 1.0 and 1.1 Professional 4 January 2nd, 2004 06:00 PM





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