Solved

ASP Session Variable empty

Posted on 1998-08-12
9
293 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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