473,406 Members | 2,451 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,406 software developers and data experts.

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_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim objConnection As OleDbConnection
Dim daContent As OleDbDataAdapter
Dim objDataReader As OleDbDataReader
Dim objCommand As New OleDbCommand
Dim mySqlStatment As String = "Select * FROM materia1Links_cl"
objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=D:\works\WEBS\edusalon\dbcontainer\datdb.md b")
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_cl"

try

objConnection.open()
objDataReader = objCommand.ExecuteReader()

DO WHILE objDataReader.Read()= true

Response.write(objDataReader("mycolum"))

loop

objDataReader.close()
objConnection.close()
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_Start with
my connection string in it and how my others form
can use it. thanks

Nov 18 '05 #1
2 3508
PRTC,
You are misunderstanding 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_Start 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_Start
Application.Add("Connection", new OleDbConnection("...."))
end sub

and in your code inside the HTML,

OleDbConnection connection = ctype(Application("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**********@hotmail.com> wrote in message
news:G7***********@fe39.usenetserver.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_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim objConnection As OleDbConnection
Dim daContent As OleDbDataAdapter
Dim objDataReader As OleDbDataReader
Dim objCommand As New OleDbCommand
Dim mySqlStatment As String = "Select * FROM materia1Links_cl"
objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\works\WEBS\edusalon\dbcontainer\datdb.md b")
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_cl"

try

objConnection.open()
objDataReader = objCommand.ExecuteReader()

DO WHILE objDataReader.Read()= true

Response.write(objDataReader("mycolum"))

loop

objDataReader.close()
objConnection.close()
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_Start 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****************@TK2MSFTNGP12.phx.gbl...
PRTC,
You are misunderstanding 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_Start 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_Start
Application.Add("Connection", new OleDbConnection("...."))
end sub

and in your code inside the HTML,

OleDbConnection connection = ctype(Application("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**********@hotmail.com> wrote in message
news:G7***********@fe39.usenetserver.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_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim objConnection As OleDbConnection
Dim daContent As OleDbDataAdapter
Dim objDataReader As OleDbDataReader
Dim objCommand As New OleDbCommand
Dim mySqlStatment As String = "Select * FROM materia1Links_cl"
objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;

Data
Source=D:\works\WEBS\edusalon\dbcontainer\datdb.md b")
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_cl"

try

objConnection.open()
objDataReader = objCommand.ExecuteReader()

DO WHILE objDataReader.Read()= true

Response.write(objDataReader("mycolum"))

loop

objDataReader.close()
objConnection.close()
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_Start
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
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...
12
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...
8
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...
5
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
2
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...
11
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...
4
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...
16
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: <%@...
8
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...
15
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.