473,480 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to change config.web file

7 New Member
<configuration>
<appSettings/>
<connectionStrings>
<add name="pedbConnectionString" connectionString="Data Source=localhost;Initial Catalog=acsdb;Persist Security Info=True;User ID=sa;Password=password123"
providerName="System.Data.SqlClient" />
</connectionStrings>



i want to change the initial catalog to lets say pedb? how do i do tat?




Before:
<add name="pedbConnectionString" connectionString="Data Source=localhost;Initial Catalog=acsdb;Persist Security Info=True;User ID=sa;Password=password123"

After:
<add name="pedbConnectionString" connectionString="Data Source=localhost;Initial Catalog=pedb;Persist Security Info=True;User ID=sa;Password=password123"


thanks in advance
Jul 23 '07 #1
10 1912
Plater
7,872 Recognized Expert Expert
config.web should not be changed by it's own running code.
Self-modifying code is naughty.
What you could do is store it like this:
Expand|Select|Wrap|Line Numbers
  1. <add name="pedbConnectionString" connectionString="Data Source=localhost;Initial Catalog=#!CATALOG#;Persist Security Info=True;User ID=sa;Password=password123" />
  2.  
Or something and then when you grab the string, use a .Replace() to replace "#!CATALOG#" with the value you want.
Jul 23 '07 #2
RoninZA
78 New Member
BUT, if you are trying to modify another application's code (like firing a seperate EXE to change the original config file), try using the System.Web.Configuration.WebConfigurationManager object for websites, or System.Configuration.ConfigurationManager object for windows apps (remember to include System.Configuration reference).

These objects' Open...() methods will give you a System.Configuration.Configuration object, which has all the configuration information parsed quite nicely :)

I have a nifty class which I could paste here, but that would defeat the purpose, now wouldn't it?

Happy hunting!
Jul 23 '07 #3
dingjie
7 New Member
config.web should not be changed by it's own running code.
Self-modifying code is naughty.
What you could do is store it like this:
Expand|Select|Wrap|Line Numbers
  1. <add name="pedbConnectionString" connectionString="Data Source=localhost;Initial Catalog=#!CATALOG#;Persist Security Info=True;User ID=sa;Password=password123" />
  2.  
Or something and then when you grab the string, use a .Replace() to replace "#!CATALOG#" with the value you want.
how to replace the connection string in web.config?
Jul 24 '07 #4
christopherpond
26 New Member
Not sure what you are trying to do but you can store multiple connection strings and access them by name in the web.config file.
Jul 24 '07 #5
dingjie
7 New Member
BUT, if you are trying to modify another application's code (like firing a seperate EXE to change the original config file), try using the System.Web.Configuration.WebConfigurationManager object for websites, or System.Configuration.ConfigurationManager object for windows apps (remember to include System.Configuration reference).

These objects' Open...() methods will give you a System.Configuration.Configuration object, which has all the configuration information parsed quite nicely :)

I have a nifty class which I could paste here, but that would defeat the purpose, now wouldn't it?

Happy hunting!
that would be a taking out method. what abt an update method?
Jul 24 '07 #6
dingjie
7 New Member
Not sure what you are trying to do but you can store multiple connection strings and access them by name in the web.config file.

can you please elaborate?

i am trying to change the connection string.
Jul 24 '07 #7
dip_developer
648 Recognized Expert Contributor
can you please elaborate?

i am trying to change the connection string.

hi dingjie......
it's not a good idea to edit web.config at runtime.Realize that any change you make to web.config will result in the application being restarted on your webserver. This means all the sessions go bye-bye. The best way to store dynamic data like this, doesn't have to be in web.config, rather is in a database, or a xml config file you can parse at runtime, without interrupting the flow of things.

but if you are using .net framework 2.0 then try this......

http://www.extremeexperts.com/Net/Ar...PNETPart2.aspx
Jul 24 '07 #8
christopherpond
26 New Member
Why exactly are you trying to change it? Just curious, is it based upon some runtime data? Is it not known at design time? I usually keep 2 connection strings in my web.config. One for production and one for local development. I then pull them by name.

If your example is that you want to load a particular database based upon runtime parameters say UserID (if each user has its own database) this would not work.
Jul 24 '07 #9
dingjie
7 New Member
erm.. u see ar.. i got this system. when different schools login the database changes to cater to that school.
Jul 25 '07 #10
christopherpond
26 New Member
Not sure if this is a bad coding solution but how about create a method called GetConnectionString which can access the connection string from the web.config and in that method could replace the catalog with the one you need. Just need to make sure all calls for connection string goes through this method.

All I can think of or build the whole connection string in code.
Jul 25 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4869
by: Scanner2001 | last post by:
I have a service with settings in the app.config file. I would like to be able to change these settings without restarting the service. Something similar to a web.config with web services. Whenever...
3
13383
by: Frankie | last post by:
I'm writing a small utility app (C# Windows forms) used to create new ASP.NET Web sites. This utility needs to be able to change existing values in an existing Web.config. Please note: I do NOT...
5
2909
by: who be dat? | last post by:
Hello all. I'm writing an application that is writing trace information that can be viewed in trace.axd. I would like to rename this and use a different name specific to my application. I know...
2
2378
by: Joel D Kraft | last post by:
I'm using controls in my ASP.NET application from a couple of vendors. Between the vendors and thier versioning, I've set up subfolders under my bin directory: bin bin\Infragistics\v5.2...
5
1560
by: stand__sure | last post by:
I had occasion tonight to write an installer class that changed something in a config file tonight (I had never had a need to do it, but happened upon a "How To" article that explained it in terms...
1
1926
by: Iwan Petrow | last post by:
Hi, I have dynamic properties (for checkboxes Checked property which I use in Option dialog box) . After I change checkboxes check properties I use DOM to save the changed values in the config...
2
1328
by: VB Programmer | last post by:
I used to be able to change minor settings in my web.config file when it was on the web server, such as <appSettings> elements. In ASP.NET 2.0 I noticed that there is a web.config AND a...
4
2197
by: Ravi Ambros Wallau | last post by:
Hi: We developed a set of ASP.NET Web Applications that never runs in stand-alone mode, but always inside a portal (Rainbow Portal). All modules are copied on that portal. My question is: load...
0
3751
by: Alias | last post by:
Hi - I have a site that runs on a development and production server. I'd like to programmatically change the connection string the provider uses in the web.config file and have the provider use...
0
1035
by: Michael Bray | last post by:
I've found a change in SP1 that doesn't seem to make sense to me, but seems to be there nonetheless. The situation is this... I have an application that stores it's configuration in a file in...
0
7055
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
6920
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...
0
7061
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
7030
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...
0
5367
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,...
1
4799
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
4503
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...
1
574
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
210
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.