Solved

ASP Session Variable empty

Posted on 1998-08-12
9
287 Views
Last Modified: 2011-09-20
I am working with ASP ( Very new to the stuff), IIS, Visual InterDev, NTFS Windows NT 4.x
.Here is the issue :
I am connecting to a local ACCESS database.  I have defined an Session Variable  in sub Session_onstart procedure.

<!-- This is in global.asa -->
Sub Session_onStart()
     Session("testVar")="Test Value"
End Sub

<!-- this is in default.htm -->

<h1>Test the Session Variable <%=Session("TestVar")%> </h1>

Above statement is giving an empty value. It does not retrieve the value.
I have tried the following.
1) changed the permission of the global.asa file to have Read(RX) permission
2) Went to inetpub\mydir\myproj ( where my project reside) and change the security permission on Intranet and Network users to read (RX)

and it still is NOT able to access the session variable.
Please Help Very Urgent.....

0
Comment
Question by:anuravi
9 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 1845239
I it really default.htm, or do you mean default.asp ?
Are both files in the same directory ? (the default.asp should be in the same or in a subdirectory of the directory where global.asa is).
Does your browser accept cookies ? (it should, otherwise sessionvariables will not work with ASP).

Anyway, I don't use global.asa in my ASP-applications.

If I want certain variables/functions/etc to be read, I put them in a file called "whatever.inc" and include it in the ASP I want it to read.

<!--#include file="MyInclude.inc"-->
0
 
LVL 3

Author Comment

by:anuravi
ID: 1845240
sybe,
I appreciate your answer. The Code is in default.htm.
And yes the browser accepts cookies.
The file default.htm is in the same directory as of global.asa.
If I donot use global.asa, My question then is there any way to get connected to a DATABASE (DSN entry - odbc). As I am connecting to a remote database via DSN.  Any help would be greatly appreciated.
Thanking u in anticipation
0
 
LVL 10

Accepted Solution

by:
MasseyM earned 200 total points
ID: 1845241
Yep, getting connected to a DSN database can be written in the page code... The same code in global.as acan be used in the regular page.

if you need more help on this, email me masseym@hotmail.com

as for the session variables, rename your default.htm default.asp (just for conformity) and make sure, like sybe said, that they are in the same directory...
0
 
LVL 28

Expert Comment

by:sybe
ID: 1845242
ASP pages must have the extension .asp, they won't work if they have extension .htm

To connect to a database on a remote server take the following steps:

Create an ODBC connection on the machine with the webserver is running to the database. Remember the name you gave it.

================================
In the ASP-code do this:

<%

'Create a connection to the database:

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=YourODBCName"

'Make a recordset:

Set RS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM TABLE"
' Put in the SQL statement you want to be executed
RS.Open strSQL, Conn, 1, 1


'Display the records:

Do While Not RS.EOF
  Response.write RS("Field1") & ", " & RS("Field2") & "<br>"
  ' give it the HTML layout you want, this example is very simple
RS.MoveNext
Loop
RS.Close

%>


What I do is make a file Connect.inc which creates the Connection:

===========
Connect.inc
==========
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=YourODBCName"
%>

I include that file at the top of each ASP that uses the connection:

==========
<!-- #include file="Connect.inc" -->
<%
.rest of code here
%>
=========

Remember that include statement are HTML, and must be outside of the <% %> tags


0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Author Comment

by:anuravi
ID: 1845243
I Like the answer. Thank you very much sybe. I have graded sybe for the answer
0
 
LVL 28

Expert Comment

by:sybe
ID: 1845244
Sorry, but you gave MasseyM the points
0
 
LVL 3

Author Comment

by:anuravi
ID: 1845245
How Do I transfer it to sybe?? I do not have any idea.
0
 
LVL 28

Expert Comment

by:sybe
ID: 1845246
Try it at the customer service area
0
 
LVL 7

Expert Comment

by:linda101698
ID: 1845247
Once a question is graded the only way I have to award points is to post a question for the expert who should have been graded.   Look for the question in this topic area directed to sybe.

Linda Gardner
Customer Service @ Experts Exchange

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now