0

I want to override the ConfigurationManager.ConnectionStrings.IsReadOnly();

because of which i get the Connectionstring is Readonly. when I tried to edit that on Run time

ConnectionStringSettings connectionStringSettingInstance = 
                            new ConnectionStringSettings(connectionName,
                                                         ConnectionStringBuilded,
                                                         ConnectionProvider);
ConfigurationManager.ConnectionStrings.Add(connectionStringSettingInstance);  
Oded
  • 489,969
  • 99
  • 883
  • 1,009
user824910
  • 1,067
  • 6
  • 16
  • 38

1 Answers1

2

You got it all mixed up.

A readonly collection will remain readonly no matter what you attempt.
It's not a switch, it is a definition.

Furthermore, that collection comes from the app.config, and you cannot add dynamically to that collection because it is physical: everything that appears in the ConfigurationManager static class at runtime is actually physically written in the app.config

That's the theory, in practice however, you can cheat this by using reflection.

So, all hope is not lost. But when you come to a point where you try to cheat the framework into doing something it was not meant to do, it is time to rethink your design.

Community
  • 1
  • 1
Louis Kottmann
  • 16,268
  • 4
  • 64
  • 88