Solved

ASP Session Variable empty

Posted on 1998-08-12
9
289 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

773 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