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

Can you restart a ASP.NET application in the Application_Start eve

Can you restart an ASP.NET application in the Application_Start event when an
error occurs so the next request for the application will fire the
Application_Start event again?

This would allow the application to recover without intervention if the
problem is a database server is temporarily offline or other external source
of data being loaded in the Application_Start event having a problem. I
usually set up a SQL Dependency in the Application_Start event and get data
that changes infrequently. I need this initialization to occur even when
previous page requests failed and the database server is available again. I
would also like it to display an error message to let the page requestor know
there is a problem and to exit and reopen IE and retry the page in a few
minutes.
--
Thanks,
Mark
Mar 20 '07 #1
4 2152
You could try loading then saving the web.config file, that would restart
the app.

"masmith" <ma*****@discussions.microsoft.comwrote in message
news:09**********************************@microsof t.com...
Can you restart an ASP.NET application in the Application_Start event when
an
error occurs so the next request for the application will fire the
Application_Start event again?

This would allow the application to recover without intervention if the
problem is a database server is temporarily offline or other external
source
of data being loaded in the Application_Start event having a problem. I
usually set up a SQL Dependency in the Application_Start event and get
data
that changes infrequently. I need this initialization to occur even when
previous page requests failed and the database server is available again.
I
would also like it to display an error message to let the page requestor
know
there is a problem and to exit and reopen IE and retry the page in a few
minutes.
--
Thanks,
Mark

Mar 20 '07 #2
Perhaps with an HTTP Handler, but this is a lot of overkill for something
you can catch and avoid. Move the code that occasionally errors to the
SEssion_Start and set it up as a singleton, so it does not have to run over
and over again when everything is correct. You then get the best of both
worlds.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*********************************************
Think outside the box!
*********************************************
"masmith" <ma*****@discussions.microsoft.comwrote in message
news:09**********************************@microsof t.com...
Can you restart an ASP.NET application in the Application_Start event when
an
error occurs so the next request for the application will fire the
Application_Start event again?

This would allow the application to recover without intervention if the
problem is a database server is temporarily offline or other external
source
of data being loaded in the Application_Start event having a problem. I
usually set up a SQL Dependency in the Application_Start event and get
data
that changes infrequently. I need this initialization to occur even when
previous page requests failed and the database server is available again.
I
would also like it to display an error message to let the page requestor
know
there is a problem and to exit and reopen IE and retry the page in a few
minutes.
--
Thanks,
Mark
Mar 20 '07 #3
I was hoping for something cleaner and simpler, such as resetting the
application. Instead I have the code executing the startup code in the
Applcation_Start and in the Session_Start if an Application["ErrMsg"] in not
null. If any errors are found initializing the Application objects or
starting the SQLDependency, I set the Application["ErrMsg"] to a appropriate
string for the error.
--
Mark
"Cowboy (Gregory A. Beamer)" wrote:
Perhaps with an HTTP Handler, but this is a lot of overkill for something
you can catch and avoid. Move the code that occasionally errors to the
SEssion_Start and set it up as a singleton, so it does not have to run over
and over again when everything is correct. You then get the best of both
worlds.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*********************************************
Think outside the box!
*********************************************
"masmith" <ma*****@discussions.microsoft.comwrote in message
news:09**********************************@microsof t.com...
Can you restart an ASP.NET application in the Application_Start event when
an
error occurs so the next request for the application will fire the
Application_Start event again?

This would allow the application to recover without intervention if the
problem is a database server is temporarily offline or other external
source
of data being loaded in the Application_Start event having a problem. I
usually set up a SQL Dependency in the Application_Start event and get
data
that changes infrequently. I need this initialization to occur even when
previous page requests failed and the database server is available again.
I
would also like it to display an error message to let the page requestor
know
there is a problem and to exit and reopen IE and retry the page in a few
minutes.
--
Thanks,
Mark

Mar 21 '07 #4
The hard part with this idea is you are trying to capture an application
from within an application and then have it reset itself. It might be
possible to destroy the app from within the app, but that would likely throw
its own error. You could possibly climb up the stack and cause the aspnet
worker process to kill the application, but that could error, as well.

To capture outside of the stack, you could use an HTTP Handler, but the
handler would have to test and throw or engage some form of app watcher. If
you are testing the SQL conn anyway, it makes more sense, to me, to go the
path of least resistance and test the connection before trying to set it, or
try ... catching it and setting an app variable so the person cannot hit
anything if the SQL conn is hosed. To make sure this scenario "reboots" when
available, it is best to use Session_Start, as every session start will hit
the site and run the code. If you do it as a Singleton, you will only
instantiate once, which is far less intrusive for application level code.

The cleanest I can think of is something like this:

public class Singleton
{
private Singleton()
{
'Code here that sets up app variables that might fail
'(or call routine)
}

private static Singleton _single;

public static GetSingleton()
{
if (_single == null)
_single = new Singleton();

return _single;
}
}

To call

Session_Start()
{
'Test things that might fail

if(noFailingConditions)
{
'You can use this anywhere in code an it always returns the same one
Singleton single = Singleton.GetSingleton();

'Code here to do stuff that is in the Singleton
}
}

I think this is pretty straightforward. In addition, it sets you up for
success and not failure. And, it does not require climbing all the way
outside of your app domain to control your app domain.

An even better model is to set up the protection code in the Singleton and
have check routines on the Singleton that retry broken bits. In this manner,
you do not have to restart applications due to failure, as the app becomes
somewhat self-healing.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*********************************************
Think outside the box!
*********************************************
"masmith" <ma*****@discussions.microsoft.comwrote in message
news:F5**********************************@microsof t.com...
>I was hoping for something cleaner and simpler, such as resetting the
application. Instead I have the code executing the startup code in the
Applcation_Start and in the Session_Start if an Application["ErrMsg"] in
not
null. If any errors are found initializing the Application objects or
starting the SQLDependency, I set the Application["ErrMsg"] to a
appropriate
string for the error.
--
Mark
"Cowboy (Gregory A. Beamer)" wrote:
>Perhaps with an HTTP Handler, but this is a lot of overkill for something
you can catch and avoid. Move the code that occasionally errors to the
SEssion_Start and set it up as a singleton, so it does not have to run
over
and over again when everything is correct. You then get the best of both
worlds.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*********************************************
Think outside the box!
*********************************************
"masmith" <ma*****@discussions.microsoft.comwrote in message
news:09**********************************@microso ft.com...
Can you restart an ASP.NET application in the Application_Start event
when
an
error occurs so the next request for the application will fire the
Application_Start event again?

This would allow the application to recover without intervention if the
problem is a database server is temporarily offline or other external
source
of data being loaded in the Application_Start event having a problem.
I
usually set up a SQL Dependency in the Application_Start event and get
data
that changes infrequently. I need this initialization to occur even
when
previous page requests failed and the database server is available
again.
I
would also like it to display an error message to let the page
requestor
know
there is a problem and to exit and reopen IE and retry the page in a
few
minutes.
--
Thanks,
Mark

Mar 21 '07 #5

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

Similar topics

3
by: alexB | last post by:
On my ASP.NET application, restarting the application through IIS doesn't always fire the Application_Start() event. Is there a trick to this? Restarting IIS is not an option since there are...
1
by: localhost | last post by:
In the Application_OnStart, I make some data calls and place the results in the HTTP cache. Sometimes, the database is not available when the application starts up, so I want to sleep for 20...
18
by: amdishigh | last post by:
We are experiencing the following problems concerning ASP.NET: our ASP.NET application, written in .NET 1.1 platform, and hosted in IIS 5.0 environment, experience frequent session timeout problem....
3
by: SL | last post by:
All, As I understand it, a single application (i.e. IIS virtual directory) in ASP.NET may in fact have more than one corresponding HttpApplicationState object (more or less one per server...
6
by: jim | last post by:
Hi All, I like to know the life cycle of an ASP .NET Application( incudieng server application, such as .NET Web Service). That means from initialization to fully running and how to reboot it or...
3
by: ad | last post by:
I want to renew all values of Application and Session. How can I restart application in program?
1
by: newjazzharmony | last post by:
When I run an ASP dot net application in debug mode and put a breakpoint inside the Application_Start event (in global.asax.cs), sometimes it stops there and sometimes it doesn't. I was under...
2
by: Janet | last post by:
Hi, I've used the Application_Start() to load some codes onto the Web Server. However, I need to reboot my machine every time if I've added some codes to the database, and for it to load up to...
1
by: nicerun | last post by:
I'm using the Application_Start event at Global.asax.cs to invoke thread that do some job. I know that Application_Start event occurs when the very first request to Web Application received. -...
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
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
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
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
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,...
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...
0
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...

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.