473,513 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating web.config.ConnectionStrings at runtime

Hi all,

I want to add a new connection string to my webservice web.config file at
runtime :

ConnectionStringSettings connStringsSettings = new
ConnectionStringSettings("sys_connection_string", myConnString);

System.Configuration.Configuration cfgRootWebConfig =
WebConfigurationManager.OpenWebConfiguration(null) ;

cfgRootWebConfig.ConnectionStrings.ConnectionStrin gs.Add(connStringsSettings);

cfgRootWebConfig.Save(); <-- Here the exception !!!???
But I'm getting the following exception :
System.Configuration.ConfigurationErrorsException: An error occurred loading
a configuration file: Access to the path
'C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727 \\Config\\lxwcx05m.tmp' is
denied.
(C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727 \\Config\\web.config) --->
System.UnauthorizedAccessException: Access to the path
'C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727 \\Config\\lxwcx05m.tmp' is
denied.\n at System.IO.__Error.WinIOError(Int32 errorCode, String
maybeFullPath)\n at System.IO.FileStream.Init(String path, FileMode mode,
FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32
bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String
msgPath, Boolean bFromProxy)\n at System.IO.FileStream..ctor(String path,
FileMode mode, FileAccess access)\n at
System.CodeDom.Compiler.TempFileCollection.EnsureT empNameCreated()\n at
System.CodeDom.Compiler.TempFileCollection.AddExte nsion(String
fileExtension, Boolean keepFile)\n at
System.CodeDom.Compiler.TempFileCollection.AddExte nsion(String
fileExtension)\n at
System.Configuration.Internal.WriteFileContext..ct or(String filename, String
templateFilename)\n at
System.Configuration.Internal.InternalConfigHost.S taticOpenStreamForWrite(String
streamName, String templateStreamName, Object& writeContext, Boolean
assertPermissions)\n at
System.Configuration.Internal.InternalConfigHost.S ystem.Configuration.Internal.IInternalConfigHost.O penStreamForWrite(String
streamName, String templateStreamName, Object& writeContext, Boolean
assertPermissions)\n at
System.Configuration.Internal.InternalConfigHost.S ystem.Configuration.Internal.IInternalConfigHost.O penStreamForWrite(String
streamName, String templateStreamName, Object& writeContext)\n at
System.Configuration.Internal.DelegatingConfigHost .OpenStreamForWrite(String
streamName, String templateStreamName, Object& writeContext)\n at
System.Configuration.UpdateConfigHost.OpenStreamFo rWrite(String streamName,
String templateStreamName, Object& writeContext)\n at
System.Configuration.MgmtConfigurationRecord.SaveA s(String filename,
ConfigurationSaveMode saveMode, Boolean forceUpdateAll)\n --- End of inner
exception stack trace ---\n at
System.Configuration.MgmtConfigurationRecord.SaveA s(String filename,
ConfigurationSaveMode saveMode, Boolean forceUpdateAll)\n at
System.Configuration.Configuration.SaveAsImpl(Stri ng filename,
ConfigurationSaveMode saveMode, Boolean forceSaveAll)\n at
System.Configuration.Configuration.Save()\n at
Cims.Web.Configuration.ReadConnectionString() in
d:\\CIMS.NET\\Cims.Net\\App_Code\\CimsService.asmx .cs:line 4805\n at
Cims.Web.CmsWebService..ctor() in
d:\\CIMS.NET\\Cims.Net\\App_Code\\CimsService.asmx .cs:line 67\n ---
What am I doing wrong ?

I'm using .NET Framework 2.0 on a Win XP Pro SP2.
In C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\ \Config\\ folder, the
ASP.NET user has only read rights. I think it's enough (see
http://msdn2.microsoft.com/en-us/library/kwzs111e.aspx ).
Root web.config has read+write permissions for current user + ASP.NET user.

Thnx for any advice
Mar 5 '07 #1
2 7279
Hi,

Did you find the solution to this problem? I have the same issue.

Fatima

Mar 6 '07 #2
Sorry for the delay.

I found a solution : instead of using null (getting a readOnly config file,
cached I think), now I'm using "~" to get the root web.config and I can
write to it.

old code : System.Configuration.Configuration cfgRootWebConfig =
WebConfigurationManager.OpenWebConfiguration(null) ;

new : System.Configuration.Configuration cfgRootWebConfig =
WebConfigurationManager.OpenWebConfiguration("~");

<fa***********@gmail.comwrote in message
news:11**********************@t69g2000cwt.googlegr oups.com...
Hi,

Did you find the solution to this problem? I have the same issue.

Fatima

Mar 14 '07 #3

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

Similar topics

3
3859
by: Nuno | last post by:
At first, I was trying to encrypt ConnectionStrings in my app.config and still be able to modify my datasets. So, i had to modify the Settings.Designer.cs file to handle the decryption aspect in...
10
9417
by: Ryan | last post by:
I've created a custom configuration section that inherits (naturally) from System.Configuration.ConfigurationSection. The configuration section is working 99% fine, however I keep coming across a...
10
2026
by: eagle | last post by:
I have a web.config in my application that contains the connection strings to all my datasources. I want to move these connection strings to another web config up the folder hierarchy so that all...
1
1232
by: huntco | last post by:
I have a "business logic" dll that has a connectionString and some my.mysettings.default values that I need to change based on the system the dll is running on (i.e.: a development, test vs. a...
4
1147
by: Raymon Du | last post by:
Hi, I am getting the following exception every time I modified web.config, the only way to fix it is to recycle application pool or restart IIS, but I don't want to do that all the times. TIA
3
2907
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I cut and paste the following code from msdn help page which it just introduces view and multiview server controls. Here is what I do: in vs studio 2005, File --New Web Site, it...
0
954
by: iprogram2008 | last post by:
I have a huge complex app.config and one of the sections in the config is connection strings. I have a dot net class that uses this app.config and a com interop is generated for this dot net class....
3
1627
by: ThatsIT.net.au | last post by:
I have been looking into web config file section replacements I have set it buy putting in the line into the deploy section connectionStrings=connectionStrings.config; I then have a file by that...
18
3920
by: navyjax2 | last post by:
What if your event handler has to be nonstatic?
0
7267
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
7553
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
5697
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
5100
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
4754
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...
0
3247
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...
0
1609
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 ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
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.