473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

application variables not loading

Dan
I'm not able to access my variables that I've set in my
global.asax. Here is my simple code. Note: Error message
is below.

[[ global.asax ]]

<%@ Page Language="c#" %>

<script language="c#" runat="server">

string DbAccessString = "Provider=Microsoft.Jet.OleDb.4.0;
Data
Source=E:\\Users\\canadianmoneysaver\\public_html\ \testing\
\survey.mdb";

</script>
[[ db_access_aspx ]]

<%@ Page Language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="c#" runat="server">

void Page_Load()
{
string strConnection =
DbAccessString;
data_src.Text =
strConnection;
OleDbConnection
objConnection = new OleDbConnection(strConnection);
try
{

objConnection.Open();

con_open.Text = "Connection opened success.<br />";

objConnection.Close();

con_close.Text = "Connection closed<br />";
}
catch (Exception e)
{

con_open.Text = "Connection failed to open.<br />";

con_close.Text=e.ToString();
}
}

</script>

<html>
<head>
<title></title>
</head>
<body>

<h4>Testing data connection

<asp:Label id="data_src"
Text="" runat="server"/></h4>

<asp:Label id="con_open"
Text="" runat="server"/><br />

<asp:Label id="con_close"
Text="" runat="server"/><br />
PATH: <%= Server.MapPath("/testing")%> <br />
</body>
</html>
[[ ERROR MESSAGE ]]

Compiler Error Message: CS0103: The name 'DbAccessString'
does not exist in the class or
namespace 'ASP.db_access_aspx'

Nov 17 '05 #1
1 1328
Make your variable public and static then you will be able to access it
Global.DbAccessString.

The Global is the class created behind your global.aspx. It's the same class
as any other class in C# so you need to treat it the same way.

You can not refer to variables declared in other classes without explicitly
providing instance of the class.

George.

"Dan" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
I'm not able to access my variables that I've set in my
global.asax. Here is my simple code. Note: Error message
is below.

[[ global.asax ]]

<%@ Page Language="c#" %>

<script language="c#" runat="server">

string DbAccessString = "Provider=Microsoft.Jet.OleDb.4.0;
Data
Source=E:\\Users\\canadianmoneysaver\\public_html\ \testing\
\survey.mdb";

</script>
[[ db_access_aspx ]]

<%@ Page Language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="c#" runat="server">

void Page_Load()
{
string strConnection =
DbAccessString;
data_src.Text =
strConnection;
OleDbConnection
objConnection = new OleDbConnection(strConnection);
try
{

objConnection.Open();

con_open.Text = "Connection opened success.<br />";

objConnection.Close();

con_close.Text = "Connection closed<br />";
}
catch (Exception e)
{

con_open.Text = "Connection failed to open.<br />";

con_close.Text=e.ToString();
}
}

</script>

<html>
<head>
<title></title>
</head>
<body>

<h4>Testing data connection

<asp:Label id="data_src"
Text="" runat="server"/></h4>

<asp:Label id="con_open"
Text="" runat="server"/><br />

<asp:Label id="con_close"
Text="" runat="server"/><br />
PATH: <%= Server.MapPath("/testing")%> <br />
</body>
</html>
[[ ERROR MESSAGE ]]

Compiler Error Message: CS0103: The name 'DbAccessString'
does not exist in the class or
namespace 'ASP.db_access_aspx'

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: aa | last post by:
I am migrating to PHP from ASP where there are the Application Scope variables which are accessible from any page on a website and which are used, in particular, for hit counters. Is there a similar...
1
by: Daishik | last post by:
We have got a website that has been happily running on IIS 5.0 with ASP3.0, extensively using Application variables for caching. Unfortunately yesterday, we had to install .NET framework and MDAC...
2
by: KathyB | last post by:
Hi, I'm doing an asp.net app (first one) and NEED to use frames (so please don't tell me not to!). I'm loading a mainframe.htm with two aspx files (for example: left.aspx, right.asp). QUESTION:...
8
by: Anthony P. Mancini | last post by:
I'm working on a proof of concept that will ultimately be deployed on a load balancer. For the sake of a preliminary demonstration I created a C# object and marked it's attributes as Public...
7
by: Pavils Jurjans | last post by:
Hello, I wanted to get some light in the subject. As I develop ASP.NET applications, it's necessary to understand how exactly the server- communication happens. It seems like initially...
3
by: jimmygoogle | last post by:
I posted earlier with a scope problem. I think I resolved it in IE but in Firefox it still exists. Anyone have any ideas/experience with this? I attached my code sorry it is so long. You can...
11
by: Murali Krishna. Siruvuru | last post by:
Hi, For Custom Caching, we are having couple of hashtables & lists which store around 200,000 objects. This was working on Win 2003 perfect and now we added a new module which would store...
9
by: jeff | last post by:
Hi All. I realize that when my Deployed winforms application starts, Windows needs to load the .net 2 framework before control is given to my application.... Is there anyway to either ... -...
2
by: jphelan | last post by:
Ever since I successfully applied some techniques for increasing the speed of my 17 meg. Application; it has only made me hunger for more. First, let me list what I have done so far: 1. Split...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.