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!?
            Asked
            
        
        
            Active
            
        
            Viewed 2,053 times
        
    0
            
            
        
        abatishchev
        
- 98,240
 - 88
 - 296
 - 433
 
        Martin Schmeller
        
- 3
 - 3
 
- 
                    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. – Mister Epic Aug 16 '13 at 13:05
 
2 Answers
1
            Instead of passing the name of the connection string from the config file you can just pass the connection string to the ctor.
        Pawel
        
- 31,342
 - 4
 - 73
 - 104
 
0
            
            
         ConfigurationManager.RefreshSection("xxx")
EDIT:
Looks Like EF Caches, so even teh refresh doesnty work apparently. so try this EF Runtime connection strings
        Community
        
- 1
 - 1
 
        phil soady
        
- 11,043
 - 5
 - 50
 - 95
 
- 
                    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. – Martin Schmeller Aug 16 '13 at 14:07
 -