dotnet web services:
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.ConnectionStrings.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.EnsureTempNameCreated()\n at
System.CodeDom.Compiler.TempFileCollection.AddExtension(String
fileExtension, Boolean keepFile)\n at
System.CodeDom.Compiler.TempFileCollection.AddExtension(String
fileExtension)\n at
System.Configuration.Internal.WriteFileContext..ctor(String filename, String
templateFilename)\n at
System.Configuration.Internal.InternalConfigHost.StaticOpenStreamForWrite(String
streamName, String templateStreamName, Object& writeContext, Boolean
assertPermissions)\n at
System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForWrite(String
streamName, String templateStreamName, Object& writeContext, Boolean
assertPermissions)\n at
System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForWrite(String
streamName, String templateStreamName, Object& writeContext)\n at
System.Configuration.Internal.DelegatingConfigHost.OpenStreamForWrite(String
streamName, String templateStreamName, Object& writeContext)\n at
System.Configuration.UpdateConfigHost.OpenStreamForWrite(String streamName,
String templateStreamName, Object& writeContext)\n at
System.Configuration.MgmtConfigurationRecord.SaveAs(String filename,
ConfigurationSaveMode saveMode, Boolean forceUpdateAll)\n --- End of inner
exception stack trace ---\n at
System.Configuration.MgmtConfigurationRecord.SaveAs(String filename,
ConfigurationSaveMode saveMode, Boolean forceUpdateAll)\n at
System.Configuration.Configuration.SaveAsImpl(String 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