Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:19:27+00:00 2026-06-13T02:19:27+00:00

I am trying to switch different databases for a web application at Run time.

  • 0

I am trying to switch different databases for a web application at Run time.

Senario
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

                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();

                }

i am reading above connection string on a page by using ConfigurationManager.problem is the web config file is changing but after calling to another page using Response.Redirect will throw an exception .Exception is “Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack “I can realized this is something happen on cross threaded environment.My questions are

  • What is exact reason for above exception?
  • which page life circle of the Asp.net reads the setting from the web config file ?
  • What is the proper way i can implement above scenario?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:19:28+00:00Added an answer on June 13, 2026 at 2:19 am

    I am wondering why this question seems still unanswered.OK i have found some answermy self.It may be wrong but some how they are giving some meaning to me.I assume following are acceptable for my knowledge level.

    1)I don’t know the exact reason ,but this is something happen because of code is modified while an application running

    2)Based on my search WEB Config file is started to read by the application when the IIS server start.So what ever values to be modified inside WEB Config ,require to restart the IIS server to load them in to memory.We can modify the connection string dynamically but still the application will run on the previous connection string.So we need t restart the IIS to load newer one.

    Note:Modify a existing connection string is different than add a new connection string to a WEB Config.

    3)I have used a common data Base where i have authentication details for different different connection strings for Several database.WeB config has the connection string for above master database.If an user gives his authentication detail it will select his connection string and load it as new connection string .So the remaining process will be based on that connection string.

    Any new arguments for above answers are highly appreciable.I need corrections from other developers because i am very eager to learn.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have an h:inputText switch out with a different one when
I am trying to use the following method to switch to a different application:
I have different classes each with a different background. I'm trying to switch background
I'm trying to switch over to using app.yaml instead of web.xml and app-engine-web.xml. I've
I have never code in Python and trying to switch from Javascrpt/SVG. Being confused
I have a Jekyll blog, I am trying to switch from this {:lang='bash'} #!/bin/sh
I have a UITabBarConroller that I use to switch between 3 different views. This
I trying to switch my mysql database to different location. But i could not
I'm trying to make a Chrome extension that will search different cache databases for
I have a re-usable usercontrol with a viewmodel behind it. I'm trying to switch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.