473,756 Members | 2,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use global.asax?

Hi,

I want to put the namespaces and the data connection into global.asax like
this:
<%@ import namespace="Syst em.Data"%>
<%@ import namespace="Syst em.Data.OleDb"% >
<script runat="server">
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
Dim oConnection As System.Data.Ole Db.OleDbConnect ion
oConnection = New System.Data.Ole Db.OleDbConnect ion()
Dim comd As System.Data.Ole Db.OleDbCommand
Dim dtreader As System.Data.Ole Db.OleDbDataRea der
Dim sConnectionStri ng As String
sConnectionStri ng = "Provider = Microsoft.Jet.O LEDB.4.0; Data Source
= c:\mydb.mdb"
oConnection.Con nectionString = sConnectionStri ng
oConnection.Ope n()
End Sub
</script>

But how to link the global.asax file to the file (fetch.aspx) which must
fetch the data?
I did this in fetch.aspx file which generates an error "Name 'comd' is not
declared"

comd = New System.Data.Ole Db.OleDbCommand ("select count(*) from pc",
oConnection)

Thanks for helping.
Chris
May 10 '06 #1
4 2368
"Chris" <cc*@sdsd.dc> wrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..

This is one of the worst thing you can do in ASP.NET - the absolute LAST
thing you should do is to keep a connection to your RDBMS open for any
longer than is necessary, let alone for the entire lifetime of your web app.
Consider using a DAL (Data Access Layer) instead:
http://www.15seconds.com/issue/030317.htm

Also, be aware that using MS Access will severely restrict the number of
concurrent users that your web app can support - you should seriously
consider using a server RDBMS instead, preferably one with a native .NET
data provider e.g. SQL Server, MSDE / SQL Server Express, MySql etc...
May 10 '06 #2
global.asax works by itself (assuming the application root is defined as a
web application in the IIS console). You don't have to link it with a
particular page. Its purpose is to define events that will be triggered when
appropriate (ie. your code will be automatically triggered when the
application starts).

As a side note :
- you are declaring a local variable. It will be seen only in this event.
- keeping a connection around is considered as a bad practice.

The preferred way is to create the connection when needed (behing the scene
the connection is returned from a pool). This way each request use its own
connection. You can serve a number of users with fewer connections (if you
have 100 users, you'll still have currently 10 open connections if 10 users
are actually running something and others are just reading the web page they
just get).

--
Patrice

"Chris" <cc*@sdsd.dc> a écrit dans le message de news:
%2************* ***@TK2MSFTNGP0 3.phx.gbl...
Hi,

I want to put the namespaces and the data connection into global.asax like
this:
<%@ import namespace="Syst em.Data"%>
<%@ import namespace="Syst em.Data.OleDb"% >
<script runat="server">
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
Dim oConnection As System.Data.Ole Db.OleDbConnect ion
oConnection = New System.Data.Ole Db.OleDbConnect ion()
Dim comd As System.Data.Ole Db.OleDbCommand
Dim dtreader As System.Data.Ole Db.OleDbDataRea der
Dim sConnectionStri ng As String
sConnectionStri ng = "Provider = Microsoft.Jet.O LEDB.4.0; Data
Source
= c:\mydb.mdb"
oConnection.Con nectionString = sConnectionStri ng
oConnection.Ope n()
End Sub
</script>

But how to link the global.asax file to the file (fetch.aspx) which must
fetch the data?
I did this in fetch.aspx file which generates an error "Name 'comd' is not
declared"

comd = New System.Data.Ole Db.OleDbCommand ("select count(*) from pc",
oConnection)

Thanks for helping.
Chris

May 10 '06 #3
You have declared the reference for the command in the method. That
means that it's a local variable, and when it goes out of scope when the
methods ends, it's lost forever.

Creating a database connection in Application_Sta rt makes no sense
anyway, unless it's only used inside the method and properly closed. If
you would try to use the connection in the web pages, you would quickly
run into problems, as every user that requests a page will be sharing
the same connection. That means that only one user at a time can request
a page, or you will get an error message because the connection is busy.
Every page that uses the database needs it's own connection.

Chris wrote:
Hi,

I want to put the namespaces and the data connection into global.asax like
this:
<%@ import namespace="Syst em.Data"%>
<%@ import namespace="Syst em.Data.OleDb"% >
<script runat="server">
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
Dim oConnection As System.Data.Ole Db.OleDbConnect ion
oConnection = New System.Data.Ole Db.OleDbConnect ion()
Dim comd As System.Data.Ole Db.OleDbCommand
Dim dtreader As System.Data.Ole Db.OleDbDataRea der
Dim sConnectionStri ng As String
sConnectionStri ng = "Provider = Microsoft.Jet.O LEDB.4.0; Data Source
= c:\mydb.mdb"
oConnection.Con nectionString = sConnectionStri ng
oConnection.Ope n()
End Sub
</script>

But how to link the global.asax file to the file (fetch.aspx) which must
fetch the data?
I did this in fetch.aspx file which generates an error "Name 'comd' is not
declared"

comd = New System.Data.Ole Db.OleDbCommand ("select count(*) from pc",
oConnection)

Thanks for helping.
Chris

May 10 '06 #4
Ok, thanks for your advices ..;
"Göran Andersson" <gu***@guffa.co m> wrote in message
news:Ow******** ******@TK2MSFTN GP02.phx.gbl...
You have declared the reference for the command in the method. That
means that it's a local variable, and when it goes out of scope when the
methods ends, it's lost forever.

Creating a database connection in Application_Sta rt makes no sense
anyway, unless it's only used inside the method and properly closed. If
you would try to use the connection in the web pages, you would quickly
run into problems, as every user that requests a page will be sharing
the same connection. That means that only one user at a time can request
a page, or you will get an error message because the connection is busy.
Every page that uses the database needs it's own connection.

Chris wrote:
Hi,

I want to put the namespaces and the data connection into global.asax like this:
<%@ import namespace="Syst em.Data"%>
<%@ import namespace="Syst em.Data.OleDb"% >
<script runat="server">
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
Dim oConnection As System.Data.Ole Db.OleDbConnect ion
oConnection = New System.Data.Ole Db.OleDbConnect ion()
Dim comd As System.Data.Ole Db.OleDbCommand
Dim dtreader As System.Data.Ole Db.OleDbDataRea der
Dim sConnectionStri ng As String
sConnectionStri ng = "Provider = Microsoft.Jet.O LEDB.4.0; Data Source = c:\mydb.mdb"
oConnection.Con nectionString = sConnectionStri ng
oConnection.Ope n()
End Sub
</script>

But how to link the global.asax file to the file (fetch.aspx) which must
fetch the data?
I did this in fetch.aspx file which generates an error "Name 'comd' is not declared"

comd = New System.Data.Ole Db.OleDbCommand ("select count(*) from pc",
oConnection)

Thanks for helping.
Chris

May 10 '06 #5

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

Similar topics

22
3795
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
3827
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
4869
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 page. I will be grateful if some one can help me understand the difference.
5
15146
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
2
3710
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 "Global.asax.vb" file, the "Global.asax" file date modified does not change and I do not see the updated values...
11
8375
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 and I can see the code is just not execution. When running the same exact (deployed etc.) code on...
4
3047
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 things work fine. The Global.asax file is the one generated by VS 2005 - I don't try to add anything...
16
5043
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 unique things about what is happening to me.
8
13207
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'. Source Error: Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="Global" %> Source...
15
2571
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 to use shared variables in the global class. How do I convert my 1.1 applications to 2.0 without...
0
9255
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9844
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9819
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8688
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6514
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3780
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3326
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.