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

Updating configuration value in web.config after web services starts??

My question is this - is it possible to set a standard value in the
web.config file and change it later based on conditions? Why, you might
ask? I am building a web based application for inter-office usage. It
is an application where software product keys and license keys are
stored and created. We have 1/2 of the office personnel working from
within the domain, and 1/2 that disconnect and work in the field. I am
setting up replication for those that disconnect, but would like to
have them connected to the server when they are here. (That is to allow
them real time connectivity w/o extra work on the server caused by
setting up transactional replication) I hoped to set the db string
(thats the configuration value in web.config) to the large SQL server
if the connection was successful, but to change the connection string
to the MSDE db on their local machine if the prev call failed.
Any insight as to if I can set that value after testing the
connections, whether I can test the connection via c# in the web.config
itself (which I don't think is possible), or a better way that I don't
see?
Any help would be greatly appreciated!!!
Sincerely,
MisC

Nov 17 '05 #1
2 1641
MisC,

I don't think that changing the value in the web.config file is a good
idea. Rather, you should have a list of connection strings, in an order (or
named in such a way which indicates preference) that is used.

When the application first starts, the system checks the first preferred
connection string. If the connection succeeds, it uses this. If it
doesn't, it cycles to the next one.

What I don't get is why this is necessary. In reality, you should only
need one connection string in the file, and have the file differ depending
on whether or not they are outside or inside the domain. When people rejoin
the domain, they won't be accessing the application on their local pc, they
will be accessing the application on the domain, which they will need a
different url for (and not access the replicated site on their pc).

In the end, you shouldn't be accessing the web.config file for something
like this. You should just deploy the correct web.config file, and have the
app use that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"MisConFit8" <mi********@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
My question is this - is it possible to set a standard value in the
web.config file and change it later based on conditions? Why, you might
ask? I am building a web based application for inter-office usage. It
is an application where software product keys and license keys are
stored and created. We have 1/2 of the office personnel working from
within the domain, and 1/2 that disconnect and work in the field. I am
setting up replication for those that disconnect, but would like to
have them connected to the server when they are here. (That is to allow
them real time connectivity w/o extra work on the server caused by
setting up transactional replication) I hoped to set the db string
(thats the configuration value in web.config) to the large SQL server
if the connection was successful, but to change the connection string
to the MSDE db on their local machine if the prev call failed.
Any insight as to if I can set that value after testing the
connections, whether I can test the connection via c# in the web.config
itself (which I don't think is possible), or a better way that I don't
see?
Any help would be greatly appreciated!!!
Sincerely,
MisC

Nov 17 '05 #2
MUS
Hello MisConFit8!

You need to remember onething that config file are
"read-once-cache-forever" story i.e. config file will be read as your
application starts and even if you write anything to it change wont get
reflected untill you restart your application.

As for your particular scenario, i suggest that you try a fail-over
approach by keeping as many of the connection string you want in your
config file (just a thought). If you are concerned about set of custom
elements in your config file, may be something like this can do (custom
sections):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="DatabaseRepository" type="<your_type>,
<your_type_assembly>" />
</configSections>
<DatabaseRepository>
<DataSources>
<DataSource name="sqlserver" connection-string="sqlserver-conn-str" />
<DataSource name="msde" connection-string="msde-conn-str" />
</DataSources>
</DatabaseRepository>
<configuration>

The sequence of the connection string will matter as if connection to
sql server cant be made then try out the msde connection string.

I hope this might be of some help.

Let me know in case of any inconsistancy.

Regards,

Moiz Uddin Shaikh
Software Engineer
Kalsoft (Pvt) Ltd

Nov 17 '05 #3

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

Similar topics

3
by: Florida Coder | last post by:
I have the need to store some application specific configuration data to be used by a class library and or a windows service. I would like to do this in a fashion similar to the way we do with...
6
by: chokk | last post by:
All, I am getting the following error when I try to run a form page. Can someone tell me what this is about and show me how to fix it. Thnaks. Server Error in '/' Application...
1
by: Russ | last post by:
I have a windows service written in C#, and whenever I start it up, I get the error "Configuration System failed to initialize" when ever I call ConfigurationManager.AppSettings. I tried hard...
0
by: damian.rimmer | last post by:
I'm using a custom assembly (DPE) in reporting services, but I'm having problems getting the class library to find DB configuration settings in a config file. I'm using the excellent Data...
7
by: Steven Cliff | last post by:
I have started to use the new Enterprise Library (Jan 06) and have set up a skeleton project using the DAAB. This all seems to work fine apart from when I come to secure the app.config file via...
5
by: Hardy Wang | last post by:
Hi all, I understand, in .Net 2.0 we have little bit different model to read config file from .Net 1.1. Basically I need to use WebConfigurationManager.AppSettings to read from web.config, and...
2
by: Bragadiru | last post by:
Hi all, I want to add a new connection string to my webservice web.config file at runtime : ConnectionStringSettings connStringsSettings = new...
2
by: remya1000 | last post by:
i'm using VB.NET 2003. Last time while i did a program in Vb.Net 2005, i use "Configuration". and i could read and write to that XML configuration file like the example below. CODES:...
18
by: navyjax2 | last post by:
What if your event handler has to be nonstatic?
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...
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...

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.