Agent007
Agent007

Reputation: 2750

Updating Application variable at every midnight in classic ASP

I have a classic ASP application which has connection string stored as an application variable and are initialized in Application_OnStart() event.

I want to change this connection string every midnight and have it point to other database.

I thought of something like having an XML for connection string, use C# EXE with task scheduler to change this and then restart the IIS and finally read the modified connection string from the XML in Application_OnStart(), but I do not want users to loose their sessions. And also there are huge number of places where this connection string is being used, so I can not think of adding logic to read the XML at each of those places (with a C# COM component).

Are there any ways to achieve this ? Is there any storage/event etc, to use where I can store this connection string and update it without having to restart the application ?

Any help would be really appreciated.

Upvotes: 2

Views: 400

Answers (2)

G. Stoynev
G. Stoynev

Reputation: 7783

You can use an Application-level variable that you modify using code - I don't think it'll reset users' sessions:

<%@ Language="VBScript" %> 
<% 
Application.Lock  
Application("ConnString") = "new connection string"
Application.Unlock  
%>

You can craft an ASP page that does the change. If this is something that can be automated, you could write somethign simple to call that page and schedule it.

Upvotes: 1

Servy
Servy

Reputation: 203830

When your application is started you can add a file system watcher to the config file that will be fired when it is changed. In that event handler you can modify the variable that represents the connection string.

Then you can have your executable in the task scheduler to modify the config file.

Upvotes: 1

Related Questions