Solved

ASP Session Variable empty

Posted on 1998-08-12
9
291 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

860 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