Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues on dynamically change and switching the connectionString in web Config
    primarykey
    data
    text
    <p>I am trying to switch different databases for a web application at Run time.</p> <p><strong>Senario</strong> We have one asp.net web application and different databases for different customers.I am trying to switch particular connection string value from a common database where i am keeping a mapping table for connection string ,particular customer id and password .After the successful lo gin i am piking a connection string from the common database and edit the web.config file connection string section by replacing selected connection string at run time. i am doing this by add following code to login event</p> <pre><code> conectionString = cString; Configuration openWebConfiguration = WebConfigurationManager.OpenWebConfiguration("~"); ConnectionStringsSection sections = openWebConfiguration.GetSection("connectionStrings") as ConnectionStringsSection; if (sections != null) { sections.ConnectionStrings["ConnectionStringName"].ConnectionString = conectionString; ConfigurationManager.RefreshSection("ConnectionStringName"); openWebConfiguration.Save(); } </code></pre> <p>i am reading above connection string on a page by using <code>ConfigurationManager</code>.problem is the web config file is changing but after calling to another page using <code>Response.Redirect</code> will throw an exception .Exception is "<strong>Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack</strong> "I can realized this is something happen on cross threaded environment.My questions are </p> <ul> <li>What is exact reason for above exception? </li> <li>which page life circle of the Asp.net reads the setting from the web config file ?</li> <li>What is the proper way i can implement above scenario?</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload