473,770 Members | 6,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can you restart a ASP.NET application in the Application_Sta rt eve

Can you restart an ASP.NET application in the Application_Sta rt event when an
error occurs so the next request for the application will fire the
Application_Sta rt 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_Sta rt event having a problem. I
usually set up a SQL Dependency in the Application_Sta rt 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 2174
You could try loading then saving the web.config file, that would restart
the app.

"masmith" <ma*****@discus sions.microsoft .comwrote in message
news:09******** *************** ***********@mic rosoft.com...
Can you restart an ASP.NET application in the Application_Sta rt event when
an
error occurs so the next request for the application will fire the
Application_Sta rt 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_Sta rt event having a problem. I
usually set up a SQL Dependency in the Application_Sta rt 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*****@discus sions.microsoft .comwrote in message
news:09******** *************** ***********@mic rosoft.com...
Can you restart an ASP.NET application in the Application_Sta rt event when
an
error occurs so the next request for the application will fire the
Application_Sta rt 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_Sta rt event having a problem. I
usually set up a SQL Dependency in the Application_Sta rt 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_Star t 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*****@discus sions.microsoft .comwrote in message
news:09******** *************** ***********@mic rosoft.com...
Can you restart an ASP.NET application in the Application_Sta rt event when
an
error occurs so the next request for the application will fire the
Application_Sta rt 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_Sta rt event having a problem. I
usually set up a SQL Dependency in the Application_Sta rt 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(noFailingCon ditions)
{
'You can use this anywhere in code an it always returns the same one
Singleton single = Singleton.GetSi ngleton();

'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*****@discus sions.microsoft .comwrote in message
news:F5******** *************** ***********@mic rosoft.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_Star t 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_Star t 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*****@discus sions.microsoft .comwrote in message
news:09******* *************** ************@mi crosoft.com...
Can you restart an ASP.NET application in the Application_Sta rt event
when
an
error occurs so the next request for the application will fire the
Application_Sta rt 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_Sta rt event having a problem.
I
usually set up a SQL Dependency in the Application_Sta rt 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
7815
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 other applications on the machine.
1
4137
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 seconds and then restart the entire application. What is the best way to do that? Thanks.
18
5374
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. After tracing, we find that it should be caused by "ASP.NET Application Restart" (proved by incremented counter for "Application Restarts" of "ASP.NET 1.1.4322" in "Performance" whenever the timeout happens). From MSDN documentation, we find...
3
1922
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 thread, I think). During each request, only one of these objects is exposed to the page as Page.Application. This seems to be supported by the fact that when I use the debugger, I can see the Application_Start event firing more than one time even...
6
2638
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 shut it down. Including how to establish the running environment( current working folder, ...etc) for each ASP .NET application. Because in my ASP .NET application, there are a lot of modules. Some were developed by using VC#, others using...
3
2781
by: ad | last post by:
I want to renew all values of Application and Session. How can I restart application in program?
1
2485
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 the impression that clicking the "stop" button, and then the "play" button in the visual studio GUI was essentially the same as restarting the ASP dot net application. Is this not true? Thanks, Jonathan
2
1356
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 the Web server. In VS.NET 2003, I can simple remove the compiled files fin /bin then the Application_Start() will execute. Is there a way for me to force the Application_Start() to run in VS.NET 2005?
1
3459
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. - Setting worker process count 1. Start | Programs | Administrative Tools | Internet Information Services 2. Right-click on the application pool, e.g. ‘DefaultAppPool’, and select ‘Properties’
0
9425
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
10231
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
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...
0
9871
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
8887
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...
1
7416
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
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...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
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

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.