473,564 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global ASAX

I'm trying to use the global.asax in my new web aplication proyect
using the Application start to store my connection string

GLOBAL.ASAX.vb
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
Dim objConnection As OleDbConnection
Dim daContent As OleDbDataAdapte r
Dim objDataReader As OleDbDataReader
Dim objCommand As New OleDbCommand
Dim mySqlStatment As String = "Select * FROM materia1Links_c l"
objConnection = New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0; Data
Source=D:\works \WEBS\edusalon\ dbcontainer\dat db.mdb")
End Sub

The problem is, when I try to use this code in the

Webform1.aspx

Code inside of the HTML

<Script language="vb" runat ="server"

DIM mySqlStatment AS STRING = "Select * FROM materia1Links_c l"

try

objConnection.o pen()
objDataReader = objCommand.Exec uteReader()

DO WHILE objDataReader.R ead()= true

Response.write( objDataReader(" mycolum"))

loop

objDataReader.c lose()
objConnection.c lose()
Catch e as EXCEPTION

end try
end Sub

</script>

The error generated are my variables ar not declare objConnection,
objDataReader ... I m not really sure what I'm doing wrong
I thoght that when I place my variables in the globlas asax thay going to be
available each time I open the web application
did somebody know how is the correct way to use the Application_Sta rt with
my connection string in it and how my others form
can use it. thanks

Nov 18 '05 #1
2 3515
PRTC,
You are misunderstandin g the relationship of what's happening. between the
global.asax and pages. Both of these are self-contained classes, objects
defined in one won't be automatically accessible to the other. That is the
objConnection variable you are defining in Application_Sta rt is scoped to
that function only. Other functions (like Application_End ) within
global.asax won't even be able to access it, let alone in a separate
class/page.

If you wanted to do something, you would use the Application variable to
store values and make them accessible throughout your classes/pages

Application_Sta rt
Application.Add ("Connection ", new OleDbConnection ("...."))
end sub

and in your code inside the HTML,

OleDbConnection connection = ctype(Applicati on("Connection" ),
OleDbConnection )
Now having said all of this, this isn't the right way to go about handling
connections. You would be better off using a data access layer which takes
care of all your database interactions, as opposed to letting your html code
do that kind of thing. Even if you don't go for that, you probably only
want to store the connection string in the Application variable and create
new instances of OleDbConnection as needed...having instances of objects
floating around isn't all that pretty..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"PRTC" <th**********@h otmail.com> wrote in message
news:G7******** ***@fe39.usenet server.com...
I'm trying to use the global.asax in my new web aplication proyect
using the Application start to store my connection string

GLOBAL.ASAX.vb
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
Dim objConnection As OleDbConnection
Dim daContent As OleDbDataAdapte r
Dim objDataReader As OleDbDataReader
Dim objCommand As New OleDbCommand
Dim mySqlStatment As String = "Select * FROM materia1Links_c l"
objConnection = New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0; Data Source=D:\works \WEBS\edusalon\ dbcontainer\dat db.mdb")
End Sub

The problem is, when I try to use this code in the

Webform1.aspx

Code inside of the HTML

<Script language="vb" runat ="server"

DIM mySqlStatment AS STRING = "Select * FROM materia1Links_c l"

try

objConnection.o pen()
objDataReader = objCommand.Exec uteReader()

DO WHILE objDataReader.R ead()= true

Response.write( objDataReader(" mycolum"))

loop

objDataReader.c lose()
objConnection.c lose()
Catch e as EXCEPTION

end try
end Sub

</script>

The error generated are my variables ar not declare objConnection,
objDataReader ... I m not really sure what I'm doing wrong
I thoght that when I place my variables in the globlas asax thay going to be available each time I open the web application
did somebody know how is the correct way to use the Application_Sta rt with
my connection string in it and how my others form
can use it. thanks

Nov 18 '05 #2
Thanks for the help thats what Im looking for, trying to understand the use
of
Global.asax
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
PRTC,
You are misunderstandin g the relationship of what's happening. between the
global.asax and pages. Both of these are self-contained classes, objects
defined in one won't be automatically accessible to the other. That is
the
objConnection variable you are defining in Application_Sta rt is scoped to
that function only. Other functions (like Application_End ) within
global.asax won't even be able to access it, let alone in a separate
class/page.

If you wanted to do something, you would use the Application variable to
store values and make them accessible throughout your classes/pages

Application_Sta rt
Application.Add ("Connection ", new OleDbConnection ("...."))
end sub

and in your code inside the HTML,

OleDbConnection connection = ctype(Applicati on("Connection" ),
OleDbConnection )
Now having said all of this, this isn't the right way to go about handling
connections. You would be better off using a data access layer which
takes
care of all your database interactions, as opposed to letting your html
code
do that kind of thing. Even if you don't go for that, you probably only
want to store the connection string in the Application variable and create
new instances of OleDbConnection as needed...having instances of objects
floating around isn't all that pretty..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"PRTC" <th**********@h otmail.com> wrote in message
news:G7******** ***@fe39.usenet server.com...
I'm trying to use the global.asax in my new web aplication proyect
using the Application start to store my connection string

GLOBAL.ASAX.vb
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
Dim objConnection As OleDbConnection
Dim daContent As OleDbDataAdapte r
Dim objDataReader As OleDbDataReader
Dim objCommand As New OleDbCommand
Dim mySqlStatment As String = "Select * FROM materia1Links_c l"
objConnection = New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;

Data
Source=D:\works \WEBS\edusalon\ dbcontainer\dat db.mdb")
End Sub

The problem is, when I try to use this code in the

Webform1.aspx

Code inside of the HTML

<Script language="vb" runat ="server"

DIM mySqlStatment AS STRING = "Select * FROM materia1Links_c l"

try

objConnection.o pen()
objDataReader = objCommand.Exec uteReader()

DO WHILE objDataReader.R ead()= true

Response.write( objDataReader(" mycolum"))

loop

objDataReader.c lose()
objConnection.c lose()
Catch e as EXCEPTION

end try
end Sub

</script>

The error generated are my variables ar not declare objConnection,
objDataReader ... I m not really sure what I'm doing wrong
I thoght that when I place my variables in the globlas asax thay going to

be
available each time I open the web application
did somebody know how is the correct way to use the Application_Sta rt
with
my connection string in it and how my others form
can use it. thanks



Nov 18 '05 #3

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

Similar topics

22
3750
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to manipulate them. It starts > and ends with <script></script> tags. > > Yours looks like a compiled version of it.
12
3805
by: John M | last post by:
Hello, On Microsoft Visual Studio .NET 2003, I want to use some global elements, that can be used in each one of my pages. i.e I put a oleDBConnection on global.asax.vb How can I use it (the oleDBConnection on global.asa.vb) at the other aspx pages ?
8
4853
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical differences in the way both the objects are handled by IIS. Are both objects stored in different memory spaces? I can access both the objects in my web...
5
15013
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
2
3693
by: Steve | last post by:
I am new to this newsgroup & to .NET in general. I have been playing around with Visual Studio .NET, building and rendering web pages using VB "code behind" files. My problem / question is; How do I ensure that changes made to the "Global.asax.vb" file are immediately reflected in the "Global.asax" file? After I change to the...
11
8336
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the generated code on a W2K3 server the application_start and any other event on the global.asax file won't fire. I added tracing and logging to make sure...
4
3025
by: Al Santino | last post by:
Hello, I've created a simple C# web services project using Visual Studio 2005. My service compiles and runs correctly when called by remote clients. I'm able to step through the service in the debugger unless I add a Global.asax file. When I do that and then try to run the debugger I receive error 403. If I remove the Global.asax file...
16
5018
by: thefritz_j | last post by:
We just converted our VS2003 1.1 VB web project (which was working fine) to VS2005 2.0 and now I get: Parser Error Message: Could not load type '<Namespace>.'. Source Error: Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="<Namespace>." %> I've done a lot of things I've found on the web to no avial, but here are some...
8
13181
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project compiles & runs fine locally, but when I copy to the production machine, I get this error: Parser Error Message: Could not load type 'Global'....
15
2537
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax code file. In 1.1 I could have a code behind file for the global.asax file. This allow for shared variables of the Global class. Note: I use these shared variables for read only values that are set at application start. It would appear the 2.0 doesn't like you...
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.