Solved

ASP Session Variable empty

Posted on 1998-08-12
9
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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 …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

726 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