473,385 Members | 1,736 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,385 software developers and data experts.

How do I show an error happening in Application_Start ?

Hi

What can you do with the errors occuring in global.asax in Application_Start
(or Init) ? What is the best practice here ? What's the elegant solution in
this case ?

For now (I'm learning) I can think of caching the error(s) and then when the
start page finally shows, it should check that particular cache and show
whatever is inside. This could maybe be combined with some kind of logging
in a text file.

From my tests, any errors in Application_Start are simply discarded, and the
Start page shows as if nothing happened....

Thank you.
Alex
Nov 19 '05 #1
3 1394
Me again - I'll try to be more explicit - if the error is in
Application_Start, I understand that the error will occur ONLY ONCE, after
I'm done with editing the global_asax file. When I run the project again, it
won't even pass by there, so in this case if I need to rely on some value
set in Application_Start I will be screwed.

So I thought that this means that, to avoid this possibility, it is actually
not a good thing to have code in "Application_Start", but rather in "Init".
I read that the Init event is raised each time a new instance is created
(already this is *NOT* a very good thing, because I might want to execute
that code only once, and not once for each instance). However, to my grand
surprise, the same thing happens - my code, which is set to provoke an
error, is executed, again, only once - when I "F5" again in VS.Net, the
execution does not even pass by INIT. Is this NOT a new instance ???

Then I thought: Let's imagine that I need to cache a 'Settings' table to be
shared across all instances of my application, so I write code for reading
that table in "Application_Start".

Let's say that this table belongs to the database "A" on server "SA". Let's
say that the rest of my app works with tables in the database "B" on server
"SB". What happens in the case where I start the app normally, and then SA
fails and I need to read that table again because the cache has been cleared
by the system ? Since the app will never pass thru "Application_Start"
again.... what can I do short of restarting SA and asking *ALL* the users to
restart their applications ?
What if one of the many users does not close the application ? That would
mean that all instances but one have been closed, and that would mean that
my application is still not closed i.e. I cannot execute the code in
Application_Start.

Sorry, I'm very confused about this - Application vs. Instances, and error
handling, not to mention that not even INIT is executed on each run. Could
you please be so kind to clarify this for me ?

Thank you for reading this long post.
Alex.
Nov 19 '05 #2
Hi,
my suggestion is to create an object, that has method for filling the table,
that you want to be available in the whole app. This object also has method
that gets that table. This method checks if the table is already in an
application variable and if not, gets it from DB and places it in the app
variable(using the method for filling the table). If it is already there, it
simply gets it and returns the result.
In the Application_Start event handler, you just have to call the first
method, I described. Every time in the code, you need data from the table,
call the second method.
Hope that works for you.
Regards,
Kostadin Kostov

"msnews.microsoft.com" wrote:
Me again - I'll try to be more explicit - if the error is in
Application_Start, I understand that the error will occur ONLY ONCE, after
I'm done with editing the global_asax file. When I run the project again, it
won't even pass by there, so in this case if I need to rely on some value
set in Application_Start I will be screwed.

So I thought that this means that, to avoid this possibility, it is actually
not a good thing to have code in "Application_Start", but rather in "Init".
I read that the Init event is raised each time a new instance is created
(already this is *NOT* a very good thing, because I might want to execute
that code only once, and not once for each instance). However, to my grand
surprise, the same thing happens - my code, which is set to provoke an
error, is executed, again, only once - when I "F5" again in VS.Net, the
execution does not even pass by INIT. Is this NOT a new instance ???

Then I thought: Let's imagine that I need to cache a 'Settings' table to be
shared across all instances of my application, so I write code for reading
that table in "Application_Start".

Let's say that this table belongs to the database "A" on server "SA". Let's
say that the rest of my app works with tables in the database "B" on server
"SB". What happens in the case where I start the app normally, and then SA
fails and I need to read that table again because the cache has been cleared
by the system ? Since the app will never pass thru "Application_Start"
again.... what can I do short of restarting SA and asking *ALL* the users to
restart their applications ?
What if one of the many users does not close the application ? That would
mean that all instances but one have been closed, and that would mean that
my application is still not closed i.e. I cannot execute the code in
Application_Start.

Sorry, I'm very confused about this - Application vs. Instances, and error
handling, not to mention that not even INIT is executed on each run. Could
you please be so kind to clarify this for me ?

Thank you for reading this long post.
Alex.

Nov 19 '05 #3
Let's start with just the Init event questions:

Each HttpApplication instance does fire Init when it instantiates, but
these objects are then pooled and used throughout the life of the
application. It's possible then that you'll only see Init fired a
handful of times.

http://odetocode.com/Articles/89.aspx
Make sense?

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 31 Jan 2005 00:45:39 -0500, "msnews.microsoft.com"
<RE***********************@yahoo.com> wrote:
Me again - I'll try to be more explicit - if the error is in
Application_Start, I understand that the error will occur ONLY ONCE, after
I'm done with editing the global_asax file. When I run the project again, it
won't even pass by there, so in this case if I need to rely on some value
set in Application_Start I will be screwed.

So I thought that this means that, to avoid this possibility, it is actually
not a good thing to have code in "Application_Start", but rather in "Init".
I read that the Init event is raised each time a new instance is created
(already this is *NOT* a very good thing, because I might want to execute
that code only once, and not once for each instance). However, to my grand
surprise, the same thing happens - my code, which is set to provoke an
error, is executed, again, only once - when I "F5" again in VS.Net, the
execution does not even pass by INIT. Is this NOT a new instance ???

Then I thought: Let's imagine that I need to cache a 'Settings' table to be
shared across all instances of my application, so I write code for reading
that table in "Application_Start".

Let's say that this table belongs to the database "A" on server "SA". Let's
say that the rest of my app works with tables in the database "B" on server
"SB". What happens in the case where I start the app normally, and then SA
fails and I need to read that table again because the cache has been cleared
by the system ? Since the app will never pass thru "Application_Start"
again.... what can I do short of restarting SA and asking *ALL* the users to
restart their applications ?
What if one of the many users does not close the application ? That would
mean that all instances but one have been closed, and that would mean that
my application is still not closed i.e. I cannot execute the code in
Application_Start.

Sorry, I'm very confused about this - Application vs. Instances, and error
handling, not to mention that not even INIT is executed on each run. Could
you please be so kind to clarify this for me ?

Thank you for reading this long post.
Alex.


Nov 19 '05 #4

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

Similar topics

1
by: Oddball | last post by:
What on earth causes an ArgumentNullException? I've checked the spelling of my table and column names, those are fine. The relation I created one line above this one creates fine. I can't...
1
by: AW | last post by:
Hi all, In my Application_Start, I'm initializing the application. ASP.Net calls my Application_Start on the first request, not on the following ones. However, if something goes wrong in my...
0
by: Jon | last post by:
I have custom error handling configured for my application. In web.config I have: <customErrors defaultRedirect="ErrorDisplay.aspx" mode="On"> <error statusCode="404" redirect="Error404.htm"/>...
5
by: Nathan Sokalski | last post by:
When I view my index.aspx page any time after the first time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize)...
4
by: Marc Missire | last post by:
Hi, I have an issue below I'd love help with, involving a static variable, Application_Start, and a background thread. In global.asax.cs I have a static variable (outside any method) with a...
8
by: bryan | last post by:
Is there any way I can get the application path (the one returned by Request.ApplicationPath) in the Application_Start method in Global.asax? Request is not valid there. On a related note, is there...
4
by: NoNickname | last post by:
Hi, I need to get a string from a COM component at application start. (It's a Long Story and I cannot change this fact.) In ASP.NET 1.1, I simply called this COM component in Global.asax.cs...
6
by: Joe Befumo | last post by:
I just created the default personal site project in Visual Studio 2005, and it worked perfectly -- very nice. Next, I'd like to import some stat-capture code that I have working in a Visual Studio...
7
by: Christian Blackburn | last post by:
Hi Gang, Let me start by saying I'm using Visual Web Developer 2005 and ASP.net 2.0. Is there something I have to do to get my Global.asax fire when my application loads. If I set a breakpoint...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.