0

how can I force DbContext to reread a Connection string from config without restart my application? I Change the Password in the config Connection string. I create a new instance of DbContext with the Name=xxxx constructor. But in DbContext.Database.ConnectionString still is the old Password!?

1
  • The config file is read in at start-up, none of the values can be modified until your application or website is restarted. If you edit your web.config, your app pool will be restarted automatically. Commented Aug 16, 2013 at 13:05

2 Answers 2

1

Instead of passing the name of the connection string from the config file you can just pass the connection string to the ctor.

Sign up to request clarification or add additional context in comments.

Comments

0
 ConfigurationManager.RefreshSection("xxx") 

EDIT:

Looks Like EF Caches, so even teh refresh doesnty work apparently. so try this EF Runtime connection strings

2 Comments

I already tried it but this doesn't refresh the DbContext. It seems that EF internally caches the connection string when the application starts up. Every new instance of DbContext uses the old Connection string as it was on app startup.
then you will be forced to dynaically pass connection to context

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.